Page 1 of 3

SwitchOrCopyFields: Switches or Copies song data fields

Posted: Mon Jan 30, 2006 8:28 pm
by Steegy
SwitchOrCopyFields' own forum post.

The SwitchFields script switches specified song data field pairs.
It is also possible to copy one field into another (instead of switching).

Utility functions Utility_General.vbs and Utility_Controls.vbs are necessary for the script to run.
You can download these from and put them in MediaMonkey's Scripts folder.

The script consists of 1 script file ("SwitchOrCopyFields.vbs").

The script has been updated. You will need to update "Utility_Controls.vbs" too! (once, this will be done automaticly... :wink: )

SwitchOrCopyFields.vbs (for the Scripts folder)

Code: Select all

' MediaMonkey Script 
' NAME: SwitchOrCopyFields v1.0 
'  Switches specified song data field pairs: almost all possible song data fields in the library.
'  (Change UpdateFileTags to True if you also want to update the file's tags)
'  It is also possible to copy one field to another (instead of switching them)
' AUTHOR: Steegy aka RC 
' DATE  : 31.01.2006
' UPDATE: 16.02.2006
' - Copy script to MediaMonkey's "Scripts" folder and add the following in the
'    file Scripts\Scripts.ini (remove the ' in front)
'DisplayName=Switch Or Copy Fields
'Description=Switch Or Copy Fields
'>> ForumURL:
'>> ScriptName: SwitchOrCopyFields
'>> VersionNumber: 1.0
'>> Author: Steegy aka RC (Ruben Castelein)

Dim UpdateFileTags
    UpdateFileTags = True


ExecuteGlobal GetFileContents(SDB.ApplicationPath & "Scripts\Utility_General.vbs")
ExecuteGlobal GetFileContents(SDB.ApplicationPath & "Scripts\Utility_Controls.vbs")

Sub SwitchOrCopyFields

  Dim mySongList
      Set mySongList = SDB.SelectedSongList

  If MySongList.Count = 0 Then
    Set MySongList = SDB.AllVisibleSongList
    If MySongList.Count = 0 Then
      SDB.MessageBox "Nothing selected!", mtError, Array(mbOK)
      Exit Sub
    End If
  End If

  Set SDB.Objects("MySongList") = MySongList

  Set Form = SDB.UI.NewForm 
  Form.Common.SetRect 100, 100, 360, 140 
  Form.BorderStyle  = 3   ' Resizable 
  Form.FormPosition = 4   ' Screen Center 
  Form.Caption = "Switch or Copy Fields in Library/Files" 

  Dim DropDownValueSwitch1, DropDownValueSwitch2, SwitchValuesButton, CloseButton
  Set DropDownValueSwitch1 = CreateDropDown(Form, 20, 20, 130, 20, "DropDownValueSwitch1")
  Set DropDownValueSwitch2 = CreateDropDown(Form, 200, 20, 130, 20, "DropDownValueSwitch2")
  Dim SwitchLabel
  Set SwitchLabel = CreateLabel(Form, "<-->", 165, 23, 20, 20)
  SwitchLabel.Common.ControlName = "SwitchLabel"

  Dim CopyOnlyCheckBox
  Set CopyOnlyCheckBox = CreateCheckBox(Form, "Copy only (instead of switch)", 165, 43, 200, 20)
  CopyOnlyCheckBox.Common.ControlName = "CopyOnlyCheckBox"
  Script.RegisterEvent CopyOnlyCheckBox.Common, "OnClick", "CopyOnlyCheckBoxClick" 

  Set SwitchValuesButton = CreateButton(Form, "Switch Fields", 20, 75, 150, 20, Script.ScriptPath, "SwitchFields_Action")
  SwitchValuesButton.Default = True
  SwitchValuesButton.Common.ControlName = "SwitchValuesButton"

  Set CloseButton = CreateButton(Form, "Close", 182, 75, 150, 20, "", "")
  CloseButton.Cancel = True
  CloseButton.ModalResult = 2

  FillDropDownFromArray DropDownValueSwitch1, SongDataFields
  FillDropDownFromArray DropDownValueSwitch2, SongDataFields


End Sub

Sub CopyOnlyCheckBoxClick(CheckBox)

  Dim Form, SwitchLabel
  Set Form = CheckBox.Common.TopParent.Common
  Set SwitchLabel = Form.ChildControl("SwitchLabel")

  If CheckBox.Checked Then
    SwitchLabel.Caption = "---->"
    SwitchLabel.Caption = "<-->"
  End If

End Sub


Sub SwitchFields_Action(Btn)

  Dim DropDownValueSwitch1, DropDownValueSwitch2
  Set DropDownValueSwitch1 = Btn.Common.Parent.Common.ChildControl("DropDownValueSwitch1")
  Set DropDownValueSwitch2 = Btn.Common.Parent.Common.ChildControl("DropDownValueSwitch2")

  Dim TempString

  Dim MySongList
      Set MySongList = SDB.Objects("MySongList")

  Dim Form, CopyOnlyCheckBox
  Set Form = Btn.Common.TopParent.Common
  Set CopyOnlyCheckBox = Form.ChildControl("CopyOnlyCheckBox")

  Dim CopyOnly
  CopyOnly = CopyOnlyCheckBox.Checked

  If ArrayContains(SongDataFields, DropDownValueSwitch1.Text) Then
    If ArrayContains(SongDataFields, DropDownValueSwitch2.Text) Then

      Dim i, MySong
      For i = 0 To MySongList.Count - 1
        Set MySong = MySongList.Item(i)

        If CopyOnly Then
          Execute("MySong." & DropDownValueSwitch2.Text & " = MySong." & DropDownValueSwitch1.Text)
          Execute("TempString = MySong." & DropDownValueSwitch1.Text)
          Execute("MySong." & DropDownValueSwitch1.Text & " = MySong." & DropDownValueSwitch2.Text)
          Execute("MySong." & DropDownValueSwitch2.Text & " = TempString")
        End If
        If UpdateFileTags = True Then
        End If

      If CopyOnly Then
        SDB.MessageBox "Copied " & DropDownValueSwitch1.Text & " to " & DropDownValueSwitch2.Text & " tags.", mtInformation, Array(mbOK)
        SDB.MessageBox "Switched " & DropDownValueSwitch1.Text & " and " & DropDownValueSwitch2.Text & " tags.", mtInformation, Array(mbOK)
      End If
    End If
  End If

End Sub


Function GetFileContents(FilePath)

  GetFileContents = ""

  Dim ForReading, TristateUseDefault
      ForReading = 1
      TristateUseDefault = -2

  Dim FSO
      Set FSO = CreateObject("Scripting.FileSystemObject")
  If Not FSO.FileExists(FilePath) Then Exit Function
  Dim File
      Set File = FSO.GetFile(FilePath)

  Dim FileStream
      Set FileStream = File.OpenAsTextStream(ForReading, TristateUseDefault)

  GetFileContents = FileStream.ReadAll

End Function

Posted: Mon Jan 07, 2008 9:42 am
by Macarena

using MM3, up to date. how can I play around with the <Path> tag stored in the library, too? I would like to store the path in <Custom 1>, let say...

Problem With Switch or Copy Fields in MM3

Posted: Wed Jan 16, 2008 4:05 pm
by latinmusiclover
Problem With Switch or Copy Fields in MM3
In MM2.5 you could type the first few letters of the field in the list box and the script filled in the field name. For example, "mo" gave you "Mood", "cu" gave you "Custom1". Then you clicked on "Switch" and the script worked.

In MM3, I noticed the following behaviour:
If you type the first few letter (as in the example above), you get the field names, but when you click on "Switch" nothing happens. By testing I found that you have to have the field name EXACTLY as it appears in the list. So, in the above example, you have to start with an upper-case "M" and "C", or you have to scroll down and select the field name.

I also noticed that in MM2.5 when you typed the first letter you could "arrow down" to the field name. For example, "M" gave "Medialabel". Then I used the arrow down to go to "Mood". In MM3, if you type the first letter then press the down arrow, the list goes back to the top of the list (begins with "A")

Posted: Thu Feb 21, 2008 7:04 pm
by coolmalayalee
Thanks. I installed it following the exact directions. I use MM3 in Windows Vista. When I execute the script I get the following error. I am also posting in the original script thread you pointed out.


Can you help me figure out what is the problem?

Posted: Thu Feb 21, 2008 9:07 pm
by nynaevelan
When you installed the script, did you also install the two complimentary scripts listed in first post??


Posted: Thu Feb 21, 2008 9:08 pm
by coolmalayalee
Yes I did.

Posted: Thu Feb 21, 2008 9:17 pm
by nynaevelan
That line is referencing the Scripts\Utility_General.vbs script, did you name it exactly as it is in the switchorcopy script?


Posted: Thu Feb 21, 2008 9:23 pm
by coolmalayalee
It is exactly named as such.... those files I downloaded and saved directly into the scripts folder without any changes... and I checked it again.. the names are exactly as it is..

Posted: Thu Feb 21, 2008 9:33 pm
by nynaevelan
I think we are going to have to wait for Steegy or one of the other experts. One other suggestion, are you running MM as an administrator? Try closing it, going to Windows Explorer, navigating to the MM folder, right clicking on the mediamonkey.exe file and selecting run as administrator. I read in one of the other forums that this may resolve the permission issues. You could also try it with UAC turned off. I'm not sure if this is what is preventing the script from running because I always run it with UAC off. I think it was Spacefish who stated once you run MM one time as an administrator, the problems are resolved.


Posted: Thu Feb 21, 2008 9:37 pm
by coolmalayalee
I just switched of MM and restarted it as administrator. The problem still exists. I also downloaded and replaced the Utility_General and Utility_Controls again just in case... and the problem still persist...

Posted: Thu Feb 21, 2008 9:49 pm
by nynaevelan
I'm afraid I am out of my league, sorry :oops:


Posted: Thu Feb 21, 2008 9:50 pm
by coolmalayalee
No problem.. I will wait for someone else to respond... thank you so much for your response though.. I really appreciate that..

Posted: Sun Apr 13, 2008 11:14 pm
by nohitter151
coolmalayalee wrote:No problem.. I will wait for someone else to respond... thank you so much for your response though.. I really appreciate that..
I think I know the problem. If you click the links above and just download the files (instead of going manually and copying/pasting), you will download the wrong thing because the links are pointing to the wrong location.

Try these links instead: ... ntrols.vbs ... eneral.vbs

Posted: Mon Apr 14, 2008 1:37 pm
by coolmalayalee
nohitter151 wrote: I think I know the problem. If you click the links above and just download the files (instead of going manually and copying/pasting), you will download the wrong thing because the links are pointing to the wrong location.

Try these links instead: ... ntrols.vbs ... eneral.vbs
Thanks.. it now works perfect... !!! Thanks for your help..

Posted: Tue Apr 15, 2008 9:28 am
by grayflannelsuit
Great script! One small problem though - if I copy from Year to OriginalYear and the Year field has a date like 8/8/78, only the four-digit year gets copied.