Introduction to scripting

From MediaMonkey Wiki
Jump to navigation Jump to search

How to create a custom MediaMonkey script

  1. Create a file in Scripts folder, e.g. ‘MyScripts.vbs’.
  2. Write a VB script there and put a callable code to some procedure, e.g.
    Sub CallMe
    ‘ … write some code here
    End Sub</source>
  3. Define the new script in Scripts.ini file (see below how to do it).

You can get more information about scripting in general at [1] (for example VBScript and JScript documentation is there).

In order to work with MediaMonkey’s objects from your scripts, there is 'SDB' object always present so that you can access its properties and methods. In case you work outside of MediaMonkey’s scripts (e.g. you create an ASP page) you can create this object by the following code:

Dim SDB
Set SDB = CreateObject( "SongsDB.SDBApplication")

'MediaMonkey init.vbs' file is always executed before your script and therefore it contains some constants that can be later used in your script.

More information about properties and methods of SDB object about other objects and some samples can be found in [MediaMonkey Automation objects]. A good and quite complex example of a script is Export.vbs (distributed with MediaMonkey) which contains code that takes care of all export features of MediaMonkey.

Automatically called scripts

All .vbs scripts in Scripts\Auto folder are automatically checked during MM start-up and in case there is ‘OnStartup’ procedure present, it is called. This allows to add for example user interface enhancements like new menu or toolbar items, new option sheets, etc. For more information about how to do it see sample scripts and MM scripting reference.

Format of Scripts\Scripts.ini file

This file is a standard .ini file where each section defines one custom script. Section starts with a section identifier [SectionName], where ‘SectionName’ is a unique name of the script. Then follow several lines the further describe the script:

Filename
Name of a file where the script is located, e.g. ‘MyScripts.vbs’.
ProcName
Name of a procedure to be called when the script is executed in MM. This procedure must exist in the ‘Filename’ specified above.
ScriptType
Defines type of the script:
  • 0 = A standard script that appears in Tools\Scripts submenu.
  • 1 = An export script that can be found in File\Export submenu.
  • 2 = A procedure that is called whenever a new track is started. This script doesn’t appear in any menu, it’s simply called in the background. When this procedure is executed, there is 'CurrentTrack' variable of SDBSongData object defined and you can use it to get information about the track.
  • 3 = A search script. This script allows custom searched to be programmed in Auto-tag from Web dialog. This script type is a little more complex and so it has its own dedicated page.
Order
Defines the order of the script in its section. These numbers are sorted and scripts are listed according to the order then.
DisplayName
The script is listed under this name in MediaMonkey menu.
Description
This is shown as a tooltip when mouse is over the script in menu.
Language
Is usually VBScript, but can be any other scripting language, e.g. JScript.
Shortcut
Can specify a shortcut that will invoke the script in MM. You can use any of the string ‘Shift+’, ‘Ctrl+’ or ‘Alt+’ even combined together and followed either by a single letter or by a special key, which are: BkSp, Tab, Enter, Esc, Space, PgUp, PgDn, End, Home, Left, Up, Right, Down, Ins, Del.