ScriptReloader 1.0 (2009-02-25)

Download and get help for different MediaMonkey Addons.

Moderators: Peke, Gurus

Bex
Posts: 6316
Joined: Fri May 21, 2004 5:44 am
Location: Sweden

ScriptReloader 1.0 (2009-02-25)

Post by Bex » Tue Feb 24, 2009 8:44 pm

Hi fellow scripters,

Here's a new script which is purely developed for us scripters!

Are you tired of restarting MM all the time when you developing scripts?
Then the ScriptReloader is for you. The script lets you easily reload a script from the disc into MM's memory using the new script function Reload().
Wiki wrote:Method description

This method is for script development only. When called with a full script path, the script will be reloaded from disk before the its next event is called and so updated source from disk is used instead of the already loaded code from memory.

In case the ScriptPath parameter is an empty string, all strings in memory will be reloaded.

Note that by calling this method you lose all global variables of the reloaded script, their content can't be preserved. On the other hand, all registered events and SDB.Objects are preserved.

Introduced in MediaMonkey 3.1.0.1212.
It works like this:
First go to Tools->Scripts->"Select script to reload" and Select a script (or "Relaod all scripts"). The selected script gets checked and at the same time gets a new menu entry visible in right click of the main window. That's where you reload your selected script. To hide the right click menu entry simply deselect the script in Tools->Scripts->"Select script to reload".


Bug-reports, suggestions and comments are of course welcome!
Let me know what you think!


Enjoy!
/Bex
---------------------------------------------------------------------------------

Code: Select all

' MediaMonkey Script
' NAME: ScriptReloader
' VERSION: 1.0
' LAST UPDATED: 2008-02-24
' AUTHOR: Bex
' DATE : 2008-02-24

Option Explicit
Dim UI     : Set UI     = SDB.UI
Dim INI    : Set INI    = SDB.IniFile

Sub Install()
  If InvalidMM Then Exit Sub
  SDB.RefreshScriptItems
  If Not SDB.Objects("rScript") Is Nothing Then
    SDB.Objects("rScript").Visible=False
    Set SDB.Objects("rScript") = Nothing
  End If
  Dim i
  For i=0 To INI.IntValue("ScriptReloader","ScriptCnt")
    If Not SDB.Objects("rScript" & i) Is Nothing Then
      SDB.Objects("rScript" & i).Visible=False
      Set SDB.Objects("rScript") = Nothing
    End If
  Next
  Call onStartup()
End Sub

Function InvalidMM()
  If SDB.VersionString < "3.0.3" Then
     SDB.MessageBox "ScriptReloader is only compatible with MediaMonkey 3.1.0.1212 and later."& VbNewLine &_
                    "Please Update your version of MediaMonkey."& VbNewLine &_
                    "The script will not be installed.", mtWarning, Array(mbOk)
     InvalidMM=True
     Exit Function
  End If
  If SDB.VersionString = "3.1.0" Then
    On Error Resume Next
    If SDB.VersionBuild < 1212 Then
     SDB.MessageBox "ScriptReloader is only compatible with MediaMonkey 3.1.0.1212 and later."& VbNewLine &_
                    "Please Update your version of MediaMonkey."& VbNewLine &_
                    "The script will not be installed.", mtWarning, Array(mbOk)
      InvalidMM=True
      Exit Function
    End If
    On Error GoTo 0
  End If
  InvalidMM=False
End Function

Sub OnStartUp()
  If InvalidMM Then Exit Sub
  Dim fso,fld,fold,file,Mns,Mnu,i,ScriptName
  ScriptName=INI.StringValue("ScriptReloader","ScriptName")
  Set Mnu = SDB.UI.AddMenuItem( SDB.UI.Menu_Pop_TrackList, 1, 1)
  Mnu.Caption = "Reload Script " & INI.StringValue("ScriptReloader","ScriptName")
  Mnu.OnClickFunc = "Reload"
  Mnu.IconIndex = 30
  Mnu.Visible = INI.BoolValue("ScriptReloader","MnuVisible")
  Mnu.UseScript=Script.ScriptPath
  Set SDB.Objects("rScript") = Mnu

  Set Mns = SDB.UI.AddMenuItemSub( SDB.UI.Menu_Scripts, 0, 0)
  Mns.Caption = "Select Script to reload"
  Mns.IconIndex = 30
  Mns.UseScript=Script.ScriptPath

  Set Mnu=SDB.UI.AddMenuItem(Mns, 0, 0)
  Mnu.Caption = "Reload All Scripts"
  Mnu.OnClickFunc = "CheckScript"
  Mnu.Checked = Eval(ScriptName=Mnu.Caption)
  Mnu.UseScript=Script.ScriptPath
  SDB.Objects("rScript0")=Mnu

  Set fso = CreateObject("Scripting.fileSystemObject")
  fold=SDB.ScriptsPath
  If fso.FolderExists(fold) Then
    Set fld = fso.getFolder(fold)
    For Each file In fld.files
      If UCase(Right(file.Name,4))=".VBS" Then
        i=i+1
        Set Mnu=SDB.UI.AddMenuItem(Mns, 0, 0)
        Mnu.Caption = Right(file.Path,Len(file.Path)-InStrRev(file.Path,"\"))
        Mnu.OnClickFunc = "CheckScript"
        Mnu.Checked = Eval(ScriptName=Mnu.Caption)
        Mnu.UseScript=Script.ScriptPath
        SDB.Objects("rScript" & i)=Mnu
      End If
    Next
  End If
  fold=fold & "Auto\"
  If fso.FolderExists(fold) Then
    Set fld = fso.getFolder(fold)
    For Each file In fld.files
      If UCase(Right(file.Name,4))=".VBS" Then
        i=i+1
        Set Mnu=SDB.UI.AddMenuItem(Mns, 0, 0)
        Mnu.Caption = "Auto\" & Right(file.Path,Len(file.Path)-InStrRev(file.Path,"\"))
        Mnu.OnClickFunc = "CheckScript"
        Mnu.Checked = Eval(ScriptName=Mnu.Caption)
        Mnu.UseScript=Script.ScriptPath
        SDB.Objects("rScript" & i)=Mnu
      End If
    Next
  End If
  INI.IntValue("ScriptReloader","ScriptCnt")=i
End Sub

Sub CheckScript(Mnu)
  Dim i
  For i=0 To INI.IntValue("ScriptReloader","ScriptCnt")
    If Not Mnu is SDB.Objects("rScript" & i) Then
      SDB.Objects("rScript" & i).Checked=False
    End If
  Next
  Mnu.Checked= Not Mnu.Checked
  INI.StringValue("ScriptReloader","ScriptName")=Mnu.Caption
  INI.BoolValue("ScriptReloader","MnuVisible")=Mnu.Checked
  SDB.Objects("rScript").Visible=Mnu.Checked
  SDB.Objects("rScript").Caption="Reload Script " & INI.StringValue("ScriptReloader","ScriptName")
End Sub

Sub Reload(Mnu)
  Dim FullPath
  If INI.StringValue("ScriptReloader","ScriptName")="Reload All Scripts" Then
    FullPath=""
  Else
    FullPath=SDB.ScriptsPath & INI.StringValue("ScriptReloader","ScriptName")
  End If
  Script.Reload(FullPath)
End Sub

___________________________________________________________
Download:
Latest version:
Note! You must have MM 3.1.0 1212 are later to use this script!
You might need to download from the Beta forum to get the required version.

MM3 (Installer)
ScriptReloader 1.0


Installation Instructions:
- New Install or upgrade:
MM3 (Installer)
Avoid "Product installation error"
- Vista Users:
- - To be able to install scripts you must Run MM as an administrator.
- - It means that you must right click the MM icon and select "Run as administrator" even if you are logged in as an administrator.
- All Users:
- - Check in your task manager that you only have one instance of MediaMonkey.exe running.

1. Download the mmip file and double click on it.
2. Goto Tools->Options->"Select script to reload" and Select a script
3. To reload the selected script, right click in the main window and select the first menu.
Advanced Duplicate Find & Fix Find More From Same - Custom Search. | Transfer PlayStat & Copy-Paste Tags/AlbumArt between any tracks.
Tagging Inconsistencies Do you think you have your tags in order? Think again...
Play History & Stats Node Like having your Last-FM account stored locally, but more advanced.
Case & Leading Zero Fixer Works on filenames too!

All My Scripts

Peke
Posts: 11120
Joined: Tue Jun 10, 2003 7:21 pm
Location: Serbia
Contact:

Re: ScriptReloader 1.0 (2009-02-25)

Post by Peke » Wed Feb 25, 2009 7:19 pm

Great idea I was thinking to make something like that to improve debugging/testing scripts but you were faster.
Best regards,
Pavle
MM Core Developer and Admin of free MediaMonkey extensions Hosting
Image
Image
How to add Images to forum

raybeau528
Posts: 401
Joined: Thu Sep 27, 2007 4:19 pm
Location: Connecticut

Re: ScriptReloader 1.0 (2009-02-25)

Post by raybeau528 » Thu Feb 26, 2009 12:26 pm

@Bex - Great script, thanks! Works perfectly - especially after I read the instruction :)

Bex
Posts: 6316
Joined: Fri May 21, 2004 5:44 am
Location: Sweden

Re: ScriptReloader 1.0 (2009-02-25)

Post by Bex » Thu Feb 26, 2009 1:37 pm

Thank you guys!
Advanced Duplicate Find & Fix Find More From Same - Custom Search. | Transfer PlayStat & Copy-Paste Tags/AlbumArt between any tracks.
Tagging Inconsistencies Do you think you have your tags in order? Think again...
Play History & Stats Node Like having your Last-FM account stored locally, but more advanced.
Case & Leading Zero Fixer Works on filenames too!

All My Scripts

Big_Berny
Posts: 1784
Joined: Mon Nov 28, 2005 11:55 am
Location: Switzerland
Contact:

Re: ScriptReloader 1.0 (2009-02-25)

Post by Big_Berny » Thu Feb 26, 2009 1:47 pm

Great! :)
Image
Scripts in use: Genre Finder / Last.fm DJ / Magic Nodes / AutoRateAccurate / Last.FM Node
Skins in use: ZuneSkin SP / Eclipse SP
AutoRateAccurate 3.0.0 (New) - Rates all your songs in less than 5 seconds!
About me: icoaching - internet | marketing | design

das Monkey
Posts: 70
Joined: Tue Feb 12, 2008 7:11 pm

Re: ScriptReloader 1.0 (2009-02-25)

Post by das Monkey » Tue Nov 29, 2011 4:54 pm

I can't get this to work anymore. Does Script.Reload still work? I've written a few independent tests and can't seem to make it work as I expect, but I could be doing it wrong. :)

Post Reply