StartupNode: Automaticly open a node when MediaMonkey starts

Download and get help for different MediaMonkey for Windows 4 Addons.

Moderators: Peke, Gurus

Steegy
Posts: 3452
Joined: Sat Nov 05, 2005 7:17 pm

StartupNode: Automaticly open a node when MediaMonkey starts

Post by Steegy »

Functionality now built-in in MediaMonkey.
This script should not be necessary anymore.


:: 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 Sat Jun 18, 2011 4:28 pm, edited 11 times in total.
Extensions: ExternalTools, ExtractFields, SongPreviewer, LinkedTracks, CleanImport, and some other scripts (Need Help with Addons > List of All Scripts).
Steegy
Posts: 3452
Joined: Sat Nov 05, 2005 7:17 pm

Post by Steegy »

No starter script needed anymore, so I removed it.
Last edited by Steegy on Fri Mar 31, 2006 8:37 am, edited 4 times in total.
Extensions: ExternalTools, ExtractFields, SongPreviewer, LinkedTracks, CleanImport, and some other scripts (Need Help with Addons > List of All Scripts).
trixmoto
Posts: 10024
Joined: Fri Aug 26, 2005 3:28 am
Location: Hull, UK
Contact:

Post by trixmoto »

Very useful script, thanks Steegy! :)
Download my scripts at my own MediaMonkey fansite.
All the code for my website and scripts is safely backed up immediately and for free using Dropbox.
Guest

Post by Guest »

cool, thanks!

is the shell window at startup part of the script or did i do something wrong?
Steegy
Posts: 3452
Joined: Sat Nov 05, 2005 7:17 pm

Post by Steegy »

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 10:13 am, edited 1 time in total.
Extensions: ExternalTools, ExtractFields, SongPreviewer, LinkedTracks, CleanImport, and some other scripts (Need Help with Addons > List of All Scripts).
rovingcowboy
Posts: 14163
Joined: Sat Oct 25, 2003 7:57 am
Location: (Texas)
Contact:

Post by rovingcowboy »

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. My skins http://www.mediamonkey.com/forum/viewto ... =9&t=16724 for some help check on Monkey's helpful messages at http://www.mediamonkey.com/forum/viewto ... 4008#44008 MY SYSTEMS.1.Jukebox WinXp pro sp 3 version 3.5 gigabyte mb. 281 GHz amd athlon x2 240 built by me.) 2.WinXP pro sp3, vers 2.5.5 and vers 3.5 backup storage, shuttle 32a mb,734 MHz amd athlon put together by me.) 3.Dell demension, winxp pro sp3, mm3.5 spare jukebox.) 4.WinXp pro sp3, vers 3.5, dad's computer bought from computer store. )5. Samsung Galaxy A51 5G Android ) 6. amd a8-5600 apu 3.60ghz mm version 4 windows 7 pro bought from computer store.
trixmoto
Posts: 10024
Joined: Fri Aug 26, 2005 3:28 am
Location: Hull, UK
Contact:

Post by trixmoto »

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.
Download my scripts at my own MediaMonkey fansite.
All the code for my website and scripts is safely backed up immediately and for free using Dropbox.
Guest

Post by Guest »

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!!
rogerr
Posts: 106
Joined: Sat Nov 15, 2003 8:02 pm

Post by rogerr »

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?
Steegy
Posts: 3452
Joined: Sat Nov 05, 2005 7:17 pm

Post by Steegy »

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
Extensions: ExternalTools, ExtractFields, SongPreviewer, LinkedTracks, CleanImport, and some other scripts (Need Help with Addons > List of All Scripts).
rogerr
Posts: 106
Joined: Sat Nov 15, 2003 8:02 pm

Post by rogerr »

Thanks Steegy! Your first suggestion worked great!
Mhesse

Post by Mhesse »

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
Steegy
Posts: 3452
Joined: Sat Nov 05, 2005 7:17 pm

Post by Steegy »

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
Extensions: ExternalTools, ExtractFields, SongPreviewer, LinkedTracks, CleanImport, and some other scripts (Need Help with Addons > List of All Scripts).
Mhesse

Post by Mhesse »

Thanks!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
putty
Posts: 1
Joined: Sat Mar 04, 2006 12:59 pm

Post by putty »

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?
Post Reply