[MM3 Script] Simple Append [2009-04-10]

Post a reply


In an effort to prevent automatic submissions, we require that you complete the following challenge.
Smilies
:D :) :( :o :-? 8) :lol: :x :P :oops: :cry: :evil: :roll: :wink:

BBCode is ON
[img] is ON
[flash] is OFF
[url] is ON
Smilies are ON

Topic review
   

Expand view Topic review: [MM3 Script] Simple Append [2009-04-10]

Re: [MM3 Script] Simple Append [2009-04-10]

by saxguyty » Tue Oct 03, 2017 10:22 am

Teknojnky wrote: updated, added genres
genre was the only thing I wanted, but it's not actually there. there is Title, Comment, Artist, AlbumArtist,Album, Tempo, Mood, Quality and Custom 1-4

Re: [MM3 Script] Simple Append [2009-04-10]

by MusicBringer » Sat Mar 02, 2013 7:54 am

Teknojnky, Simple Append [2009-04-10] is one of my fav scripts. I use it a lot to add suffix to titles.

Nanya, a bit late I know, but I've only just seen your post.

I know nothing about coding.
Please tell me how I can make use of the Simple Insert code.
Thanks,

Re: [MM3 Script] Simple Append [2009-04-10]

by Nanya » Thu Oct 04, 2012 11:52 pm

I made some modifications to this script, which makes it more of a "Simple Insert" rather than just append and prepend.

1: Now includes option to insert in the middle of the string, just specify an index!
2: Don't want/need a space added when you insert your string? There's a checkbox for that!
3: Simplified the code that applies the new data.

If you find this code useful/helpful, please let me know, I'm new at this!

Code: Select all

Option Explicit
'==========================================================================
'
' MediaMonkey Script
'
' SCRIPTNAME: Simple Append
' INITIAL VERSION: 2009.01.09
  Dim Version : Version = "2009.04.10.1600"

' DESCRIPTION: simple dialog to append or pre-pend user text to specified field
' FORUM THREAD: http://www.mediamonkey.com/forum/viewtopic.php?f=2&t=36013

' [SimpleAppend]
' filename=simpleappend.vbs
' procname=start
' displayname=Simple Append
' language=vbscript
' scripttype=0
 
' INSTALL:
' - download install package @ http://teknojnky.googlepages.com/simpleappend.mmip
' - activate via script menu'

' Initial Release:
'   Due to apparent problem saving stringvalue with leading/trailing spaces
'   there is a space hard coded in'

' Recent Updates:
'   * fixed type error
'
'   * added genre, classifcations and custom fields'
'   * forgot to disabled resize'

  Dim MainForm, UserText, Action, Field, FieldText, Preview, SongList
  Preview = ""
  ''''''''''''''''''''''''
  Dim indexField, Index, spaceBox, Space
  Index = 0
  ''''''''''''''''''''''''
  
Sub Start()

  Set Songlist = SDB.CurrentSongList
  If Songlist.Count > 0 Then
    Set MainForm = SDB.UI.NewForm
      MainForm.Caption = "Simple Append/Pre-pend"
      MainForm.Common.SetRect 200, 200, 600, 100
      MainForm.FormPosition = 4 
      MainForm.BorderStyle = 3
      MainForm.StayOnTop = True
      MainForm.SavePositionName = "SimpleAppend"
  
    Dim DropAction
    Set DropAction = SDB.UI.NewDropDown(MainForm)
      DropAction.Common.ControlName = "Action"
      DropAction.Common.Hint = "Action"
      DropAction.Style = 2
      DropAction.Common.SetRect 10, 10, 100, 30
      DropAction.AddItem("Append (to end)")
      DropAction.AddItem("PrePend (to front)")
	  '
	  DropAction.AddItem("Insert at: ")
	  '
      If SDB.IniFile.IntValue("SimpleAppend","Action") = 0 Then
        DropAction.ItemIndex = 0
      ElseIf SDB.IniFile.IntValue("SimpleAppend","Action") = 1 Then
        DropAction.ItemIndex = 1
	  Else
	    DropAction.ItemIndex = 2
      End If
      Action = DropAction.ItemIndex
      Script.RegisterEvent DropAction, "OnChange", "PreviewIt"
        
	''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''
	Set indexField = SDB.UI.NewEdit(MainForm)
	  indexField.Common.ControlName = "Index"
	  indexField.Common.Hint = "Index in the field where the string should be added"
	  indexField.Common.SetRect 120, 10, 30, 30
	  indexField.Common.Enabled = False
	  indexField.Text = "..."
	  Script.RegisterEvent indexField, "OnChange", "PreviewIt"
	
	Set spaceBox = SDB.UI.NewCheckBox(MainForm)
	  spaceBox.Common.ControlName = "Space"
	  spaceBox.Common.Hint = "Add a space before/after your text?"
	  spaceBox.Common.SetRect 500, 10, 80, 20
	  spaceBox.Caption = "Space?"
	  spaceBox.Checked = True
	  Script.RegisterEvent spaceBox.Common, "OnClick", "PreviewIt"
	  
	''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''
	 
    Dim edtUser
    Set edtUser = SDB.UI.NewEdit(MainForm)
      edtUser.Common.ControlName = "Edit"
      edtUser.Common.Hint = "Text you wish to add"
      edtUser.Common.SetRect 160, 10, 180, 30
      If SDB.IniFile.StringValue("SimpleAppend","UserText") <> "" Then
        edtUser.Text = SDB.IniFile.StringValue("SimpleAppend","UserText")
      End If
      UserText = edtUser.Text
      Script.RegisterEvent edtUser, "OnChange", "PreviewIt"
        
    Dim lbl
    Set lbl = SDB.UI.NewLabel(MainForm)
      lbl.Caption = "into"
      lbl.Common.SetRect 346, 12, 20, 30
      
    Dim DropField
    Set DropField = SDB.UI.NewDropDown(MainForm)
      DropField.Common.ControlName = "Field"
      DropField.Common.Hint = "Field to add to"
      DropField.Style = 2
      DropField.Common.SetRect 370, 10, 120, 30
      DropField.AddItem("Title")
      DropField.AddItem("Comment")
      DropField.AddItem("Artist")
      DropField.AddItem("AlbumArtist")
      DropField.AddItem("Album")
      DropField.AddItem("Tempo")
      DropField.AddItem("Mood")
      DropField.AddItem("Quality")
      DropField.AddItem("Custom 1")
      DropField.AddItem("Custom 2")
      DropField.AddItem("Custom 3")
      DropField.AddItem("Custom 4")
      DropField.AddItem("Custom 5")
      Script.RegisterEvent DropField, "OnChange", "PreviewIt"
      If SDB.IniFile.IntValue("SimpleAppend","Field") < 1 Then
        DropField.ItemIndex = 0
      Else
        DropField.ItemIndex = SDB.IniFile.IntValue("SimpleAppend","Field")
      End If
'       Field = DropField.ItemText(DropField.ItemIndex)
      Field = DropField.ItemIndex
              
    Dim btnDoIt
    Set btnDoIt = SDB.UI.NewButton(MainForm)
      btnDoIt.Caption = "&Do It!"
      btnDoIt.Common.Hint = "Apply It Now (NO UNDO) Escape to Cancel"
      btnDoIt.ModalResult = 1
      btnDoIt.Common.SetRect 500,35,80,30
        
    Set lbl = SDB.UI.NewLabel(MainForm)
      lbl.Caption = "PREVIEWING: 1st of " & Songlist.Count
      lbl.Common.SetRect 12, 45, 120, 30
	  
   
    Dim edtPreview
    Set edtPreview = SDB.UI.NewEdit(MainForm)
      edtPreview.Common.ControlName = "Preview"
      edtPreview.Common.Hint = "Preview of the first of the selected track(s)"      
      edtPreview.Common.SetRect 140, 40, 350, 50
      edtPreview.Common.Enabled = False
      edtPreview.Text = Preview
        
    Dim btnClose
    Set btnClose = SDB.UI.NewButton(MainForm)
      btnClose.Cancel = True
      btnClose.ModalResult = 2
      btnClose.Common.SetRect 0,0,0,0
  
    If MainForm.ShowModal = 1 Then
      DoIt(MainForm)
    End If
    
    Script.UnregisterAllEvents

  End If
End Sub

Sub PreviewIt(obj)
  Dim tmp, Song
  Set tmp = obj.Common.TopParent

  Action = tmp.Common.ChildControl("Action").ItemIndex
  UserText = tmp.Common.ChildControl("Edit").Text
  Field = tmp.Common.ChildControl("Field").ItemIndex
  
  ''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''
  'if "Insert at" is selected:
  If Action = 2 Then
    If indexField.Common.Enabled = False Then
	  indexField.Text = "0"
	  indexField.Common.Enabled = True
    ElseIf isNumeric(indexField.Text) Then
      Index = indexField.Text
    Else
      Exit Sub
	End If
  Else
    indexField.Common.Enabled = False
  End If
  
  'If the spaceBox is Checked, toggle the variable
  Space = spaceBox.Checked
  If spaceBox.Checked Then
    Space = " "
  Else
    Space = ""
  End If
  '''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''
  
  If Songlist.Count > 0 Then
    Set Song = Songlist.Item(0)
  
    Select Case Field
      Case 0
        FieldText = Song.Title
      Case 1
        FieldText = Song.Comment
      Case 2
        FieldText = Song.ArtistName
      Case 3
        FieldText = Song.AlbumArtistName
      Case 4
        FieldText = Song.AlbumName
      Case 5
        FieldText = Song.Genre
      Case 6
        FieldText = Song.Tempo
      Case 7
        FieldText = Song.Mood
      Case 8
        FieldText = Song.Occasion
      Case 9
        FieldText = Song.Quality
      Case 10
        FieldText = Song.Custom1
      Case 11
        FieldText = Song.Custom2
      Case 12
        FieldText = Song.Custom3
      Case 13
        FieldText = Song.Custom4
      Case 14
        FieldText = Song.Custom5
      Case Else
        msgbox("Invalid field selected?")
    End Select
    
    If Action = 0 Then 'Append
      Preview = FieldText & Space & UserText
	ElseIf Action = 1 Then 'Prepend
	  Preview = UserText & Space & FieldText
	Else 'Insert
	  If Index = 0 Then
	    Preview = UserText & Space & Mid(FieldText,Index+1,len(FieldText))
      ElseIf Index = len(FieldText) Then
	    Preview = Mid(FieldText,1,Index) & Space & UserText
	  Else
	    Preview = Mid(FieldText,1,Index) & Space & UserText & Space & Mid(FieldText,Index+1,len(FieldText))
	  End If
    End If
    If Not tmp.Common.ChildControl("Preview") Is Nothing Then
      tmp.Common.ChildControl("Preview").Text = Preview
    End If
  End If

  SDB.IniFile.IntValue("SimpleAppend","Action") = Action
  SDB.IniFile.IntValue("SimpleAppend","Field") = Field
  SDB.IniFile.StringValue("SimpleAppend","UserText") = UserText
  
End Sub

Sub DoIt(obj)
'   msgbox("Doing It, there is no undo!")
    
  If Songlist.Count > 0 Then
    Dim Txt, Track, x, NewSongs, Song, Preview, NewField
    Set NewSongs = SDB.NewSongList
    For x = 0 to Songlist.Count-1
      Set Song = Songlist.Item(x)
	  Select Case Field
		Case 0
          FieldText = Song.Title
		Case 1
		  FieldText = Song.Comment
	    Case 2
	  	  FieldText = Song.ArtistName
	    Case 3
	  	  FieldText = Song.AlbumArtistName
	    Case 4
	  	  FieldText = Song.AlbumName
		Case 5
		  FieldText = Song.Genre
		Case 6
		  FieldText = Song.Tempo
		Case 7
		  FieldText = Song.Mood
		Case 8
		  FieldText = Song.Occasion
		Case 9
		  FieldText = Song.Quality
		Case 10
		  FieldText = Song.Custom1
		Case 11
		  FieldText = Song.Custom2
		Case 12
		  FieldText = Song.Custom3
		Case 13
		  FieldText = Song.Custom4
		Case 14
		  FieldText = Song.Custom5
		Case Else
		  msgbox("Invalid field selected?")
      End Select
      If Action = 0 Then 'Append
        NewField = FieldText & Space & UserText 
	  ElseIf Action = 1 Then 'Prepend
	    NewField = UserText & Space & FieldText
	  Else 'Insert
		If Index = 0 Then
	      NewField = UserText & Space & Mid(FieldText,Index+1,len(FieldText))
        ElseIf Index = len(FieldText) Then
	      NewField = Mid(FieldText,1,Index) & Space & UserText
	    Else
	      NewField = Mid(FieldText,1,Index) & Space & UserText & Space & Mid(FieldText,Index+1,len(FieldText))
	    End If
	  End If
	  Select Case Field
        Case 0
          Song.Title = NewField
        Case 1
          Song.Comment = NewField
        Case 2
          Song.ArtistName = NewField
        Case 3
          Song.AlbumArtistName = NewField
        Case 4
          Song.AlbumName = NewField
        Case 5
          Song.Genre = NewField
        Case 6
          Song.Tempo = NewField
        Case 7
          Song.Mood = NewField
        Case 8
          Song.Occasion = NewField
        Case 9
          Song.Quality = NewField
        Case 10
          Song.Custom1 = NewField
        Case 11
          Song.Custom2 = NewField
        Case 12
          Song.Custom3 = NewField
        Case 13
          Song.Custom4 = NewField
        Case 14
          Song.Custom5 = NewField
        Case Else
      End Select
      NewSongs.Add(Song)
      SDB.ProcessMessages
    Next
  Else
    msgbox("No Tracks Selected")
  End If  
  NewSongs.UpdateAll
End Sub

Sub Install()
  Dim scriptName : scriptName = "SimpleAppend"
  'Add scripts.ini entries
  Dim inip : inip = SDB.ApplicationPath&"Scripts\Scripts.ini"
  Dim inif : Set inif = SDB.Tools.IniFileByPath(inip)
  If Not (inif Is Nothing) Then
  	inif.StringValue(scriptName,"Filename") = "SimpleAppend.vbs"
  	inif.StringValue(scriptName,"Procname") = "Start"
  	inif.StringValue(scriptName,"DisplayName") = "Simple Append"
  	inif.StringValue(scriptName,"Description") = "Adds text to selected field"
  	inif.StringValue(scriptName,"Language") = "VBScript"
  	inif.StringValue(scriptName,"ScriptType") = "0"
  	SDB.RefreshScriptItems
  End If
End Sub


Re: [MM3 Script] Simple Append [2009-04-10]

by thefaceman » Thu Sep 15, 2011 2:58 pm

Lowlander wrote:
thefaceman wrote:I get an error - Product Installation error
See: http://www.mediamonkey.com/support/inde ... ticleid=59
WOW - That was FAST and EASY and WORKED. I greatly THANK YOU for making a bad day go better. Little bits of help like this forum really go a LONG way.

-thefaceman

Re: [MM3 Script] Simple Append [2009-04-10]

by Lowlander » Thu Sep 15, 2011 2:55 pm

thefaceman wrote:I get an error - Product Installation error
See: http://www.mediamonkey.com/support/inde ... ticleid=59

Re: [MM3 Script] Simple Append [2009-04-10]

by thefaceman » Thu Sep 15, 2011 2:49 pm

I get an error - Product Installation error. I had it on an older computer and need to install it again on my new one.

-thanks
-thefaceman

Re: [MM3 Script] Simple Append [2009-04-10]

by Eyal » Tue Dec 28, 2010 7:09 pm

Thank you for this script! Very useful for me on regular basis.

I'm currently modifying the script to add Grouping field to the list, but noticed that fields [Genre] and [Occasion] are missing from the dropdown choices:

Code: Select all

      DropField.Common.SetRect 370, 10, 120, 30
      DropField.AddItem("Title")
      DropField.AddItem("Comment")
      DropField.AddItem("Artist")
      DropField.AddItem("AlbumArtist")
      DropField.AddItem("Album")
      DropField.AddItem("Tempo")
      DropField.AddItem("Mood")
      DropField.AddItem("Quality")
      DropField.AddItem("Custom 1")
      DropField.AddItem("Custom 2")
      DropField.AddItem("Custom 3")
      DropField.AddItem("Custom 4")
      DropField.AddItem("Custom 5")
The code appends data on the fields based on this conditions:

Code: Select all

    Select Case Field
      Case 0
        FieldText = Song.Title
      Case 1
        FieldText = Song.Comment
      Case 2
        FieldText = Song.ArtistName
      Case 3
        FieldText = Song.AlbumArtistName
      Case 4
        FieldText = Song.AlbumName
      Case 5
        FieldText = Song.Genre
      Case 6
        FieldText = Song.Tempo
      Case 7
        FieldText = Song.Mood
      Case 8
        FieldText = Song.Occasion
      Case 9
        FieldText = Song.Quality
      Case 10
        FieldText = Song.Custom1
      Case 11
        FieldText = Song.Custom2
      Case 12
        FieldText = Song.Custom3
      Case 13
        FieldText = Song.Custom4
      Case 14
        FieldText = Song.Custom5
I'm glad that it didn't affect my fields (I think so) as I mostly use this script to append data to Comment and Title fiedls.

Eyal :~)

Re: [MM3 Script] Simple Append [2009-04-10]

by Sabry » Sat Oct 23, 2010 8:51 am

Thanks for this excellent script!

Re: [MM3 Script] Simple Append [2009-04-10]

by Teknojnky » Fri Apr 10, 2009 5:07 pm

fixed type mismatch error

Re: [MM3 Script] Simple Append [2009-01-12]

by reggie_mal » Sat Feb 28, 2009 11:53 am

I think it depends on what is previously in the comments field to which I am trying to append or pre-pend text. If the existing text is different for all the tracks in the selection, then there are problems, and therefore you have to do them individually!

Is there a fix?

Re: [MM3 Script] Simple Append [2009-01-12]

by reggie_mal » Sat Feb 28, 2009 11:34 am

Hi,

It's a great script. I downloaded it to replace a similar script called "Append Comment" Just one problem though ....................... occasionally it doesn't seem to work on a selection of tracks. It seems random. Sometimes there is no error message....the status bar whizzes through and indicates that "## tracks are being tagged", but nothing actually happens.

Other times I get an error

Error #13 - Microsoft VBScript runtime error
Type mismatch: '[string: "Comment"]'
File: "C:\Program Files\MediaMonkey\Scripts\SimpleAppend.vbs", Line:246, Column: 8

I figured it might have something to do with spaces or quotes or something, but when I try the same append on a single track, sometimes it works and sometimes it doesn't!!

PLEASE HELP!!

Thanks

Re: [MM3 Script] Simple Append [2009-01-12]

by MM3 monkey » Sat Jan 17, 2009 7:50 am

Thank you very much, Teknojnky. Vital!

I wish that MM would show a greyed checkbox or something to show you the difference between a bunch of tracks who's e.g comment field was empty and a bunch of tracks which had more than one different comments.

Better head over to the wishlist!

Re: [MM3 Script] Simple Append [2009-01-12]

by Teknojnky » Mon Jan 12, 2009 11:04 pm

duno about the error, not using vista im using xp x64 and its working ok here.

add genre, classifications, custom fields.

enjoy

Re: [MM3 Script] Simple Append [2009-01-12]

by nynaevelan » Mon Jan 12, 2009 10:42 pm

You're probably right because I just tried installing a script which I had installed in 1209. Guess I will have to do it manually. Thanks NH.

Nyn

Re: [MM3 Script] Simple Append [2009-01-12]

by nohitter151 » Mon Jan 12, 2009 10:37 pm

nynaevelan wrote:I get the following error when installing:



Nyn
Nyn,

I'm pretty sure that's a result of this.

Top