Execute Script out of another Script

Download and get help for different MediaMonkey Addons.

Moderators: Peke, Gurus

onkel_enno
Posts: 2146
Joined: Fri Jan 14, 2005 1:45 am
Location: Germany
Contact:

Execute Script out of another Script

Post by onkel_enno » Mon Apr 11, 2005 1:56 am

Is it anyhow possible to execute a script out of another?
I would like to do it like that:

Code: Select all

sub StartSubScripts
   Call SubScriptFile1.DoSomething
   Call SubScriptFile2.DoSomething
end sub
Does anyone know a solution?

I already tried "Execute" or "ExecuteGlobal" but if a have Variables with the same Names in each File, there is an error, because the script file isn't executed - The Source code is read in instead and then executed, and they are handled within the Procedure StartSubScripts.

Does anyone know what I mean?
SansaMonkey - for SanDisk Sansa and Rockbox Users

Please no PMs for Questions which should be asked in the Forum. Thx

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

Post by Peke » Mon Apr 11, 2005 4:12 pm

Yopu can allways use standard Routine in VBScript to call another Script
But in that Script You Must Include these two lines at the beggining of file to Init MM Script Variable SDB:

Code: Select all

Dim SDB
Set SDB = CreateObject( "SongsDB.SDBApplication")
Best regards,
Pavle
MediaMonkey Team lead QA/Tech Support guru
Admin of Free MediaMonkey addon Site HappyMonkeying
Image
Image
How to add SCREENSHOTS to forum

onkel_enno
Posts: 2146
Joined: Fri Jan 14, 2005 1:45 am
Location: Germany
Contact:

Post by onkel_enno » Tue Apr 12, 2005 12:14 am

Hi Peke,

Thanks for your reply, but that's not what I'm looking for :cry:

I created a Auto-Script which takes a look to the user-specific MM-Directory (My Music\MM ...) in a sub direktory Sripts/Auto (I created). There I want to put in all my Auto-Script and only one file in the Script/Auto-Directory of MM that executes all the other script. Do youn know what I mean?

PS I want to do this because I'm tired of always copying or moving script from directory to directory while testing new versions of MM or new scripts. Now I would have only one main source of scripts which every MM-Installation could use.
SansaMonkey - for SanDisk Sansa and Rockbox Users

Please no PMs for Questions which should be asked in the Forum. Thx

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

Post by Peke » Tue Apr 12, 2005 7:53 pm

Ok I have made you example How to make it work:

MultiScriptExec.vbs (Place it in AUTO):

Code: Select all

'==========================================================================
'
' NAME: Test VBScript Execution On MM Start
'
' AUTHOR: Peke
' DATE  : 13.04.2005
'
' COMMENT: Example How To Execute VBScript within MM Script
'
'==========================================================================

Sub OnStartup
  'make variables
  Dim WShell, Command, Result
  
  'Create Shell Object
  Set WShell = CreateObject("WScript.Shell")
'--------------------------------------------------------------------------
  'Set Shell command to execute first Script
  Command = Chr(34)&"Script1.vbs"&Chr(34)
  
  'Execute first script and report execution code in Result
  Result = WShell.Run(Command, 1, 1)
'--------------------------------------------------------------------------
  
  'If needed use Result to see if script is executed corectly
  'in case result is 0 all went OK
  
'--------------------------------------------------------------------------
  'Set Shell command to execute second Script
  Command = Chr(34)&"Script2.vbs"&Chr(34)

  'Execute second script and report execution code in Result
  Result = WShell.Run(Command, 1, 1)
'--------------------------------------------------------------------------
  
  'If needed use Result to see if script is executed corectly
  'in case result is 0 all went OK
  
End Sub
Put script1.vbs wherever you want but Include/Change full path for it in 'MultiScriptExec.vbs':

Code: Select all

'==========================================================================
'
' NAME: Example Script

'
' AUTHOR: Peke
' DATE  : 13.04.2005
'
' COMMENT: This example inits basic MM Variable Needed or any external 
'          VBScript executed outside MM(Command shell, Windows Explorer)
'          or within script as separate script.
'
' WARNING: MediaMonkey Needs to be started prior to execution of Script
'          if script is executed from Windows Explorer or command shell
'
'==========================================================================

'---< DO NOT DELETE THESE LINES FROM SCRIPT >------------------------------
'Define MM Default variable used within MM Scripting Language
Dim SDB

'Create Inits MM Object and Scripting Language
Set SDB = CreateObject( "SongsDB.SDBApplication")

'Set MM to Stay Started after Script execution
SDB.ShutdownAfterDisconnect = False

'---< DO NOT DELETE THESE LINES FROM SCRIPT >------------------------------
'---< Write Your own script below this line >------------------------------

'In This Script we will start playing just for example instead of 
'whole script
SDB.Player.Play
Put script2.vbs wherever you want but Include/Change full path for it in 'MultiScriptExec.vbs':

Code: Select all

'==========================================================================
'
' NAME: Example Script
'
' AUTHOR: Peke
' DATE  : 13.04.2005
'
' COMMENT: This example inits basic MM Variable Needed or any external 
'          VBScript executed outside MM(Command shell, Windows Explorer)
'          or within script as separate script.
'
' WARNING: MediaMonkey Needs to be started prior to execution of Script
'          if script is executed from Windows Explorer or command shell
'
'==========================================================================

'---< DO NOT DELETE THESE LINES FROM SCRIPT >------------------------------
'Define MM Default variable used within MM Scripting Language
Dim SDB

'Create Inits MM Object and Scripting Language
Set SDB = CreateObject( "SongsDB.SDBApplication")

'Set MM to Stay Started after Script execution
SDB.ShutdownAfterDisconnect = False


'---< DO NOT DELETE THESE LINES FROM SCRIPT >------------------------------
'---< Write Your own script below this line >------------------------------

'In This Script we will instruct MediaMonkey to skip to next track just for 
'example instead of whole script
SDB.Player.Next
Hope this helps. If Not ask :wink:
Best regards,
Pavle
MediaMonkey Team lead QA/Tech Support guru
Admin of Free MediaMonkey addon Site HappyMonkeying
Image
Image
How to add SCREENSHOTS to forum

onkel_enno
Posts: 2146
Joined: Fri Jan 14, 2005 1:45 am
Location: Germany
Contact:

Post by onkel_enno » Wed Apr 13, 2005 12:34 am

Thanks Peke,

that's the way I wasn't thinking of :)

The only thing that disturbs me is that in this way, for example the variable "Script.ScriptPath" isn't available because it's executed a kind of outside MediaMonkey (with WindowsScripting). I tried to replace it with "WScript.ScriptFullName" but it's not available while running MediaMonkey.
Maybe I will find a solution for that - maybe 8)

Thanks a lot
SansaMonkey - for SanDisk Sansa and Rockbox Users

Please no PMs for Questions which should be asked in the Forum. Thx

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

Post by Peke » Wed Apr 13, 2005 5:30 am

No matter what you do after

Code: Select all

'---< Write Your own script below this line >------------------------------
You can Use 'Registry' to find what ever you want and only thing needed is that you in base script set registry value with 'Script.ScriptPath' in it. Read More on that in Scripting help.
Syntax will be 'SDB.Registry.'
Best regards,
Pavle
MediaMonkey Team lead QA/Tech Support guru
Admin of Free MediaMonkey addon Site HappyMonkeying
Image
Image
How to add SCREENSHOTS to forum

onkel_enno
Posts: 2146
Joined: Fri Jan 14, 2005 1:45 am
Location: Germany
Contact:

Post by onkel_enno » Wed Apr 13, 2005 6:41 am

Here I am again :)

Script.ScriptPath includes the Script-Folder and the Script-Filename. So I would have to create/change the registry-entry for every file. I'm not sure if that's THE way. I took a constant in each script where the whole Filename incl. Folder is stored.

The worst problem is the following, I will explain it by using Magic Nodes as example.
The Magic-Nodes-Script contains the OnStartUp-Procedure which will be normally executed on startup of MediaMonkey.
When running the file by using "WshShell.Run" the procedure won't be executed because WindowsScriptHost wasn't told to execute it - you know?
OK, so I cleared the Lines "Sub OnStartUp" and "end sub" that the Script-Host executes it. The Problem is that these lines (between "sub OnStartUp" and "end sub") are always executed, each time clicking on a Magic Node :(
The Result is that I get Nodes more and more.

I made some Nodes by myself (without Magic Nodes) and there I "always" create an object what I can look for when executing the script a second time, so I don't need to create it, if it's already existing.

That might be a workaround, but not the solution.

I still believe that the only (right) way is s.th. like the following: ...

Code: Select all

sub OnStartUp
   Call SubScriptFile1.OnStartUp
   Call SubScriptFile2.OnStartUp
end sub 
... or a User-depending Auto-Script-Folder in MediaMonkey :lol:

Why can't thinks be easy? 8)

So far
Enrico
SansaMonkey - for SanDisk Sansa and Rockbox Users

Please no PMs for Questions which should be asked in the Forum. Thx

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

Post by Peke » Wed Apr 13, 2005 3:17 pm

ZIP and send it over mail to me and I'll see what is the problem exactly.

I'm not sure now that I understand this last problem completly.
Best regards,
Pavle
MediaMonkey Team lead QA/Tech Support guru
Admin of Free MediaMonkey addon Site HappyMonkeying
Image
Image
How to add SCREENSHOTS to forum

Post Reply