StartupNode: Automaticly open a node when MediaMonkey starts

Download and get help for different MediaMonkey Addons.

Moderators: Peke, Gurus

StartupNode: Automaticly open a node when MediaMonkey starts

Postby Steegy on Thu Jan 12, 2006 3:35 pm

:: StartupNode's own forum post.


Description:

The StartupNode script automaticly opens or selects the last opened or an explicitly specified tree node, when MediaMonkey starts.
To set a tree node as startup node, right click the node and choose "Set as startup node".
Settings are available in the menu Edit > StartupNode submenu.

The script needs MediaMonkey version 2.5.2 or above.


Installing automaticly:

Installer for version 1.1 (latest, updated 31.03.2006): http://home.scarlet.be/ruben.castelein/ ... ode1.1.exe
Just run the exe and follow the instructions.


Installing manually:

For people that have an older version of the script:
In this new version, the script is standalone. That means that you don't need the StoreStartupAndFavouriteNodes and starter script anymore.
Notice that the folder for the StartupNode script has changed from Scripts to Scripts\Auto.


This newer version uses new built in functionality in MediaMonkey, so it will work faster.

The script consists of 1 standalone script file ("StartupNode.vbs").

StartupNode.vbs (for the Scripts\Auto folder)
Code: Select all
'==========================================================================
'
' MediaMonkey Script
'
' NAME: StartupNode v1.1
' DESCRIPTION:
'  Automaticly opens or selects a specified tree node when MediaMonkey starts.
'
' AUTHOR: Steegy aka RC (Ruben Castelein)
' DATE  : 15.12.2005
' UPDATE: 31.03.2006
'
' INSTALL:
' - Copy script to MediaMonkey's "Scripts\Auto" folder
'
' The script needs MediaMonkey version 2.5.2 or above.
'
' The script's settings in the "Variable Configuration" section can be modified
'
'==========================================================================
'>> ForumURL: http://www.mediamonkey.com/forum/viewtopic.php?t=7490
'>> ScriptName: StartupNode
'>> VersionNumber: 1.1
'>> Author: Steegy aka RC (Ruben Castelein)
'>>>>EndOfProperties


'##############################################################################################
'%%%%%%%%%%%%%%%%%%%%%
' Script declarations:
'%%%%%%%%%%%%%%%%%%%%%
Option Explicit

Dim splitString
    splitString = "§$§$§"

Dim StartupNodeArray

Dim MessageHeader
    MessageHeader = "StartupNode:" & vbNewline & vbNewline



'##############################################################################################
'%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
' Variable Configuration: (HERE YOU CAN MAKE SOME CHANGES IF YOU WANT)
'%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
'

Dim Error_BrowseToNode
    Error_BrowseToNode = "An error occured while auto-opening the specified node. "_
                       & "Possibly, the node specification is incorrect."_
                       & vbNewline & "The node has been opened as far as possible."


Dim isStartupNodeExpanded   ' Expand (True) or don't expand (False) the startup node
    isStartupNodeExpanded = True

Dim LaunchTimerTimeout      'If the scripts gives you an error when MediaMonkey starts, then try
    LaunchTimerTimeout = 0   ' to set LaunchTimerTimeout to a higher value in milliseconds (e.g. 500)
            'This is sometimes necessary if you have a "My Computer" or "Magic Nodes"
            ' subnode as startup node (especially on slower computers)


'##############################################################################################
'%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
' The subroutines and functions that make this text file a "program":
'%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%

Sub OnStartup
  ' Starts the actual script     

  ' Registers the OnShutdown Event when the right version is installed
  If CurrentVersion >= 252 Then
    Script.RegisterEvent SDB, "OnShutdown", "setStartupNodeOnShutdown"
  End If

  ' Adds item miSetAsStartupNode to the tree node popup menu
  Dim miSetAsStartupNode
  Set miSetAsStartupNode = SDB.UI.AddMenuItem(SDB.UI.Menu_Pop_Tree,0,0)
  With miSetAsStartupNode
    .Caption = "Set as startup node"
    .OnClickFunc = "setAsStartupNode"
    .UseScript = Script.ScriptPath
    .IconIndex = 22
    If SDB.IniFile.StringValue("StartupNode", "ShowContextItem") <> "False" Then
      .Visible = True
    End If
  End With
  Set SDB.Objects("StartupNodeContextItem") = miSetAsStartupNode



  ' Adds the mStartupNode submenu and adds 3 items (miStartupNodeEnabled and miStartupNodeAutoSet and miStartupNodeHide)
  SDB.UI.AddMenuItemSep SDB.UI.Menu_Edit,0,0

  Dim mStartupNode
  Set mStartupNode = SDB.UI.addMenuItemSub(SDB.UI.Menu_Edit,0,0)
  With mStartupNode
    .Caption = "StartupNode"
    .IconIndex = 22
    .useScript = Script.ScriptPath
  End With
 
  Dim miStartupNodeEnabled
  Set miStartupNodeEnabled = SDB.UI.AddMenuItem(mStartupNode,0,0)
  With miStartupNodeEnabled
    .Caption = "StartupNode enabled"
    .Hint = "Enables StartupNode so MediaMonkey will start on the startup node"
    .OnClickFunc = "setStartupNodeEnabled"
    .UseScript = Script.ScriptPath
    If SDB.IniFile.StringValue("StartupNode", "Enabled") = "True" Then
      .Checked = True
    End If
  End With
  Set SDB.Objects("StartupNodeEnabledMenuItem") = miStartupNodeEnabled

  Dim miStartupNodeAutoSet
  Set miStartupNodeAutoSet = SDB.UI.AddMenuItem(mStartupNode,0,0)
  With miStartupNodeAutoSet
    .Caption = "Set last node as startup node"
    .Hint = "If this is set, MediaMonkey will start with the node that was last used"
    .OnClickFunc = "setStartupNodeAutoSet"
    .UseScript = Script.ScriptPath
    If SDB.IniFile.StringValue("StartupNode", "AutoSet") = "True" Then
      .Checked = True
    End If
  End With
  Set SDB.Objects("StartupNodeAutoSetMenuItem") = miStartupNodeAutoSet
  If CurrentVersion < 252 Then
    miStartupNodeAutoSet.Common.Enabled = False
  End If

  Dim miStartupNodeHide
  Set miStartupNodeHide = SDB.UI.AddMenuItem(mStartupNode,0,0)
  With miStartupNodeHide
    .Caption = "Shows node context menu item"
    .Hint = "Sets whether or not to show the node context menu item"
    .OnClickFunc = "setStartupNodeContextItemVisibility"
    .UseScript = Script.ScriptPath
    If SDB.IniFile.StringValue("StartupNode", "ShowContextItem") <> "False" Then
      .Checked = True
    End If
  End With
  If miStartupNodeHide.Checked = False Then
    SDB.Objects("StartupNodeContextItem").Visible = False
  End If



  If SDB.IniFile.StringValue("StartupNode", "Enabled") <> "True" Then Exit Sub

  If InitialiseStartupNode = False Then Exit Sub

  Dim LaunchTimer
      Set LaunchTimer = SDB.CreateTimer(LaunchTimerTimeout)
  Script.RegisterEvent LaunchTimer, "OnTimer", "LaunchTimer_OnTimer"

End Sub



Sub LaunchTimer_OnTimer(Timer)

  Script.UnregisterEvents Timer

  Dim Result
      Result = BrowseToNode(StartupNodeArray)

  If Result = False Then
    SDB.MessageBox MessageHeader & Error_BrowseToNode , mtError, Array(mbOk)
  End If

End Sub



Function InitialiseStartupNode

  InitialiseStartupNode = False

  Dim PathToNode
      PathToNode = SDB.IniFile.StringValue("StartupNode", "StartupNode")
  If PathToNode = "" Then Exit Function
 
  Dim PathToNodeArray
      PathToNodeArray = Split(PathToNode, splitString)

  StartupNodeArray = PathToNodeArray

  InitialiseStartupNode = True

End Function



Function BrowseToNode(FullPathToNode)
  ' Browses to the specified node and returns True on success.

  On Error Resume Next

  Dim Node2B
      Set Node2B = SDB.MainTree.Node_NowPlaying

  Dim i
  For i = 1 To UBound(FullPathToNode)
   
    If i > 1 Then
      Node2B.Expanded = True
      Set Node2B = SDB.MainTree.FirstChildNode(Node2B)
    End If

    If Not Node2B.Caption = FullPathToNode(i) Then
      Do
        Set Node2B = SDB.MainTree.NextSiblingNode(Node2B)
        If Err <> 0 Then Exit Function
      Loop While Node2B.Caption <> FullPathToNode(i)
    End If
  Next
 
  SDB.MainTree.CurrentNode = Node2B
  Node2B.Expanded = isStartupNodeExpanded

  BrowseToNode = True

End Function


'%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
' StartupNode properties: Enable, AutoSet and Hide
'%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
'

Sub setStartupNodeEnabled(Item)

  Item.Checked = Not Item.Checked

  If Item.Checked = True Then
    SDB.IniFile.StringValue("StartupNode", "Enabled") = "True"
  Else
    SDB.IniFile.StringValue("StartupNode", "Enabled") = "False"
  End If

End Sub



Sub setStartupNodeAutoSet(Item)

  Item.Checked = Not Item.Checked

  If Item.Checked = True Then
    SDB.IniFile.StringValue("StartupNode", "AutoSet") = "True"
  Else
    SDB.IniFile.StringValue("StartupNode", "AutoSet") = "False"
  End If

End Sub



Sub setStartupNodeContextItemVisibility(Item)

  Item.Checked = Not Item.Checked

  If Item.Checked = True Then
    SDB.Objects("StartupNodeContextItem").Visible = True
    SDB.IniFile.StringValue("StartupNode", "ShowContextItem") = "True"
  Else
    SDB.Objects("StartupNodeContextItem").Visible = False
    SDB.IniFile.StringValue("StartupNode", "ShowContextItem") = "False"
  End If

End Sub



'%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
' OnShutdown event handler: save last node as startup node (for MM 2.5.2+)
'%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
'

Sub setStartupNodeOnShutdown

  If SDB.Objects("StartupNodeAutoSetMenuItem").Checked = True Then
    Dim FavouriteName
        FavouriteName = "StartupNode"

    Dim PathToNode
        PathToNode = GetPathToNode(SDB.MainTree.CurrentNode)

    SDB.IniFile.StringValue("StartupNode", "StartupNode") = FavouriteName & splitString & PathToNode
  End If

End Sub


'%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
' setAsStartupNode
'%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
'

Sub setAsStartupNode(arg)

  Dim FavouriteName
      FavouriteName = "StartupNode"

  Dim PathToNode
      PathToNode = GetPathToNode(SDB.MainTree.CurrentNode)

  SDB.IniFile.StringValue("StartupNode", "StartupNode") = FavouriteName & splitString & PathToNode


  Dim StartupNodeEnabledMenuItem
      Set StartupNodeEnabledMenuItem = SDB.Objects("StartupNodeEnabledMenuItem")
  StartupNodeEnabledMenuItem.Checked = True
  SDB.IniFile.StringValue("StartupNode", "Enabled") = "True"

  Dim miStartupNodeAutoSet
      Set miStartupNodeAutoSet = SDB.Objects("StartupNodeAutoSetMenuItem")
  miStartupNodeAutoSet.Checked = False
  SDB.IniFile.StringValue("StartupNode", "AutoSet") = "False"

End Sub

'%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
' Some utility functions
'%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
'

Function CurrentVersion
   CurrentVersion = SDB.VersionHi & SDB.VersionLo & SDB.VersionRelease
End Function


'%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
' Functions to get the path to the wanted node
'%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
'
Function GetPathToNode(myNode)
  On Error Resume Next
  Dim myNode2
 
  Dim ParentNode
      Set ParentNode = myNode

  GetPathToNode = myNode.Caption

  Do While True

    Set myNode2 = SDB.MainTree.ParentNode(ParentNode)

    If myNode2 Is ParentNode Then
      Exit Do
    End If
    Set ParentNode = myNode2
    GetPathToNode = ParentNode.Caption & splitString & GetPathToNode

  Loop

End Function



In-depth information:

The script uses configuration entries in MediaMonkey's ini file.

Example:
Code: Select all
[StartupNode]
AutoSet=True
Enabled=True
StartupNode=StartupNode§$§$§Library§$§$§Previews
ShowContextItem=True

AutoSet: Set the last used node as startup node when you exit MediaMonkey
Enabled: Sets StartupNode enabled so it will open the defined node at startup
ShowContextItem: Show the context menu entry for tree nodes, to set that node as startup node
StartupNode: Path to the startup node
_In this example StartupNode§$§$§Library§$§$§Previews
_The first (name) is always StartupNode
_The rest is the path to the specified tree node (tree levels indicated by §$§$§), so the tree node's location is Library > Previews

These values can be changed from within MediaMonkey.

Settings submenu in MediaMonkey's Edit menu:
Image
Last edited by Steegy on Tue Apr 10, 2007 5:43 pm, edited 10 times in total.
Skinning | Scripting
Not active on the forum anymore... (sorry)
Steegy
 
Posts: 3386
Joined: Sun Nov 06, 2005 12:17 am
Location: Europe > Belgium

Postby Steegy on Thu Jan 12, 2006 3:36 pm

No starter script needed anymore, so I removed it.
Last edited by Steegy on Fri Mar 31, 2006 1:37 pm, edited 4 times in total.
Skinning | Scripting
Not active on the forum anymore... (sorry)
Steegy
 
Posts: 3386
Joined: Sun Nov 06, 2005 12:17 am
Location: Europe > Belgium

Postby trixmoto on Thu Jan 12, 2006 3:47 pm

Very useful script, thanks Steegy! :)
Loving the Monkey? - Get Gold
Check out my scripts at http://trixmoto.net including my top ten
Subscribe to my rss feed for all the latest news
trixmoto
 
Posts: 7913
Joined: Fri Aug 26, 2005 8:28 am
Location: England

Postby Guest on Thu Jan 12, 2006 11:32 pm

cool, thanks!

is the shell window at startup part of the script or did i do something wrong?
Guest
 

Postby Steegy on Fri Jan 13, 2006 1:22 pm

If you see a shell window, try using "Result = WShell.Run(Command, 0, 1)" in the starter script (now fixed).
Normally the shell window is very fast so you don't see it, but the above fix (0 and 1) makes sure that is starts hidden.

Please tell me in the case it doesn't make a difference, because I never see the shell window (so I can't reproduce). Anyway, thanks for bringing that to my attention.

Cheers
Steegy
Last edited by Steegy on Fri Jan 13, 2006 3:13 pm, edited 1 time in total.
Skinning | Scripting
Not active on the forum anymore... (sorry)
Steegy
 
Posts: 3386
Joined: Sun Nov 06, 2005 12:17 am
Location: Europe > Belgium

Postby rovingcowboy on Fri Jan 13, 2006 1:31 pm

I'm a little confused?

what does this do? does it start playing music in a node you pick when it starts monkey?

playlists are for that ?

or does it open a different node then the libriary node like the playlist node?

if so then it would close the library node and use the playlists as its start up node?
:o
roving cowboy / keith hall. just a user of media monkey not a programmer. give us all the info pertaining to your errors and someone can help you more correctly.
If you don't know what info to give then check item 14 on the helpful messages link for an idea.

Monkey's helpful messages at viewtopic.php?p=44008#44008
MY SYSTEMS.
1.Xp pro sp3, vers 3.2 jukebox, built by me) 2.WinXP pro sp3, vers 2.5.5 and vers 3.2 backup storage, put together by me.)
3.lenovo toasted motherboard so its gone.) 4.Dell is gone cause its loosing drivers and stuff. 5.WinXp pro sp3, vers 2.5.5, moms computer. Sony vaio.)
rovingcowboy
 
Posts: 9759
Joined: Sat Oct 25, 2003 12:57 pm
Location: (Texas)

Postby trixmoto on Fri Jan 13, 2006 1:42 pm

You use it to have a particular node selected when you start MM. Particularly useful if you use the my computer node and don't want to have to find the right folder (which could take a lot of clicks) each time you start up.
Loving the Monkey? - Get Gold
Check out my scripts at http://trixmoto.net including my top ten
Subscribe to my rss feed for all the latest news
trixmoto
 
Posts: 7913
Joined: Fri Aug 26, 2005 8:28 am
Location: England

Postby Guest on Sun Jan 15, 2006 4:32 am

Steegy wrote:If you see a shell window, try using "Result = WShell.Run(Command, 0, 1)" in the starter script (now fixed).
Normally the shell window is very fast so you don't see it, but the above fix (0 and 1) makes sure that is starts hidden.

Please tell me in the case it doesn't make a difference, because I never see the shell window (so I can't reproduce). Anyway, thanks for bringing that to my attention.

Cheers
Steegy


Yep that did the trick! THANKS!!
Guest
 

Postby rogerr on Wed Jan 18, 2006 12:09 am

I'd like to select the "Title" node upon startup but that does not seem to be an option. I tried:
Set TopNode = SDB.MainTree.Node_Title

but it generated an error.

Also, if you use a top node like SDB.MainTree.Node_Artist, what should the PathToNode be set to?
rogerr
 
Posts: 92
Joined: Sun Nov 16, 2003 1:02 am

Postby Steegy on Wed Jan 18, 2006 12:51 pm

Hello

The "Title" node hasn't an exposed scripting reference, what means that SDB.MainTree.Node_Title doesn't exist. (not very logical, I know)

You can use some workarounds however (all have the same effect):

Code: Select all
  Set TopNode = SDB.MainTree.Node_Library
  PathToNode = "Title"

Note that the above line expects that your title node has to caption "Title" (in English). You have to change it accordingly if you have an other MM language (e.g. "Titel" for Dutch, "Titre" for French, ...).

Code: Select all
  Set TopNode = SDB.MainTree.NextSiblingNode(SDB.MainTree.Node_Location)
  PathToNode = ""

Gets the node under the Location node on the same tree level.

Code: Select all
  Set TopNode = SDB.MainTree.PreviousSiblingNode(SDB.MainTree.Node_Artist)
  PathToNode = ""

Gets the node above the Artist node on the same tree level.

This should have answered your second question too.
PathToNode should be "" if you only want to open the TopNode.

Cheers
Steegy
Skinning | Scripting
Not active on the forum anymore... (sorry)
Steegy
 
Posts: 3386
Joined: Sun Nov 06, 2005 12:17 am
Location: Europe > Belgium

Postby rogerr on Wed Jan 18, 2006 7:08 pm

Thanks Steegy! Your first suggestion worked great!
rogerr
 
Posts: 92
Joined: Sun Nov 16, 2003 1:02 am

Postby Mhesse on Sat Jan 28, 2006 11:00 am

Hi Steegy,

thanks for your script. When I start MM, I become the error message for your StartUpNoteStarter. "Result = WShell.Run(Command, 0, 1)" it be wrong (Error 2147023741).

What can I do?

Thanks for your support.

Matthias
Mhesse
 

Postby Steegy on Sat Jan 28, 2006 1:25 pm

Hello

The WShell.Run command simply executes a file in the same way as your computer would do if you start it from Start > Run... .

The error 2147023741 means "No application is associated with the specified file for this operation."

That means that your computer is set up incorrectly to execute vbs files. One of the reasons for this can be that the default execute behaviour of these files has been changed (e.g. as a security procaution to avoid harmful files, often downloaded from malicious websites or emails).

Some solutions that might be possible:

Reassign the execute action to vbs files:
Open "Explorer" or "My Computer" > menu Tools (or Extra) > Folder Options > tab File Types.
Click the list and type "vbs" (without quotation marks). When the vbs file extension is selected, click the Advanced button, select action "Open" and click "Edit".
(If action "Open" doesn't exist, then add it.)
In the edit dialog, use the following values:
Application that is executed ... : C:\WINDOWS\System32\WScript.exe "%1" %*
Check "Use DDE"
Application: WScript
Subject: System
Click OK, OK, OK.


An easier way to possibly achieve this is to install the latest scripting runtime (5.6):
Windows XP or 2000: http://www.microsoft.com/downloads/deta ... laylang=en
Windows 98, Me, NT4.0: http://www.microsoft.com/downloads/deta ... laylang=en

Cheers
Steegy
Skinning | Scripting
Not active on the forum anymore... (sorry)
Steegy
 
Posts: 3386
Joined: Sun Nov 06, 2005 12:17 am
Location: Europe > Belgium

Postby Mhesse on Mon Jan 30, 2006 2:47 pm

Thanks!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
Mhesse
 

Postby putty on Sat Mar 04, 2006 7:16 pm

I'd love to get this functioning but it's causing some problems here.

After adding these vbs files as shown here, when I open MM I get the icon in the systray but I'm unable to restore it to full window size. The systray icon is functioning on right-click.

I get things to work again by deleting the vbs files. Any ideas?
putty
 
Posts: 1
Joined: Sat Mar 04, 2006 5:59 pm

Next

Return to Need Help with Addons?

Who is online

Users browsing this forum: Heartsbane and 6 guests