[Solved] Any way to execute a type=0 script that isn't in scritps.ini?

This forum is for questions / discussions regarding development of addons / tweaks for MediaMonkey for Windows 4.

Moderators: Gurus, Addon Administrators

pokeefe0001
Posts: 97
Joined: Thu Oct 11, 2018 4:48 pm
Location: USA, Pacific Northwest

[Solved] Any way to execute a type=0 script that isn't in scritps.ini?

Post by pokeefe0001 »

In a portable MM 4.1 installation I want/need the script UpdateLocationOfFiles.vbs to be available to anybody syncing / cloning multiple copies of the portable media but I don't want it visible to the typical user. Is there some way to execute the script if it isn't in the scripts menu?
Last edited by pokeefe0001 on Sat Dec 18, 2021 7:42 pm, edited 1 time in total.
MMV4 (1919) Portable
MMW5 (2606) Portable
Multiple Win11 x64 21H2
Multiple Win7 x32, unknown builds
pokeefe0001
Posts: 97
Joined: Thu Oct 11, 2018 4:48 pm
Location: USA, Pacific Northwest

Re: Any way to execute a type=0 script that isn't in scritps.ini?

Post by pokeefe0001 »

Since there have been no responses, let me try again with maybe a more specific question.

I would like to be able to invoke UpdateLocationOfFiles.vbs from somewhere other than Tools/Scripts. Having it be an entry under File would be ideal. I suspect there are scripts (run from Auto) that add functions under tabs. Could someone point me to one that I could cannibalize? Ideally it should be fairly simple since I'm new to both MediaMonkey and vbs scripting.

And no, it wouldn't be any easier for me to do it in MM 5 instead of MM 4 ... unless there are better examples. I don't know JavaScript and better the vbs.
MMV4 (1919) Portable
MMW5 (2606) Portable
Multiple Win11 x64 21H2
Multiple Win7 x32, unknown builds
Peke
Posts: 17446
Joined: Tue Jun 10, 2003 7:21 pm
Location: Earth
Contact:

Re: Any way to execute a type=0 script that isn't in scritps.ini?

Post by Peke »

Hi,
I guess that the best guess would be the Last.FM script :) I think it should give you an idea on how do most things from Auto.

RE MM5: There is native function when you edit media property under location to allocate new Drive letter to all files assuming that file paths are actually same.
Best regards,
Peke
MediaMonkey Team lead QA/Tech Support guru
Admin of Free MediaMonkey addon Site HappyMonkeying
Image
Image
Image
How to attach PICTURE/SCREENSHOTS to forum posts
pokeefe0001
Posts: 97
Joined: Thu Oct 11, 2018 4:48 pm
Location: USA, Pacific Northwest

Re: Any way to execute a type=0 script that isn't in scritps.ini?

Post by pokeefe0001 »

Peke wrote: Mon Aug 02, 2021 6:27 pm Hi,
I guess that the best guess would be the Last.FM script :) I think it should give you an idea on how do most things from Auto.
...
Well, I found a couple LAST.FM scripts. I assume you were referring to Last.FM Scrobbler since that's one you wrote. It, and a lot of others I found, show how to add menu items, but I haven't found any that connect to an external script. All of them have something like

Code: Select all

xyz.OnClickFunc = "SomeLocalFunction"
xyz.UseScript = Script.ScriptPath 
I assume Script.ScriptPath points to the executing script.

That won't be the case for what I want. There would be a script in Auto building the menu entry, but the invoked script would be one level up in the scripts directory. And this is for a portable MM so I don't know the path. Is there some MM object that contains the Scripts path? Or maybe something that provides the Portable path for portable implementations?
MMV4 (1919) Portable
MMW5 (2606) Portable
Multiple Win11 x64 21H2
Multiple Win7 x32, unknown builds
Peke
Posts: 17446
Joined: Tue Jun 10, 2003 7:21 pm
Location: Earth
Contact:

Re: Any way to execute a type=0 script that isn't in scritps.ini?

Post by Peke »

Hi,
Yes https://www.mediamonkey.com/wiki/ISDBAp ... criptsPath is getting you MM scripts path.

The scrpt variable you refer to is auto parsed when scrip is executed from MM4 itself and Script.ScriptPath refers to path+filename of file you are reading it from.

Code: Select all

xyz.OnClickFunc = "MyScriptFunction"
xyz.UseScript = SDB.ScriptPath 
Why don't you simply use include to add/inject additional code into script?

Code: Select all

Sub includeFile(fSpec)
    With CreateObject("Scripting.FileSystemObject")
       executeGlobal .openTextFile(fSpec).readAll()
    End With
End Sub
Or

Code: Select all

Sub includeFile(fSpec)
	'Create objects for opening text file
	Set objFSO = CreateObject("Scripting.FileSystemObject")
	Set objTextFile = objFSO.OpenTextFile(fSpec, 1)

	'Execute content of file.
	ExecuteGlobal objTextFile.ReadAll

	'CLose file
	objTextFile.Close

	'Clean up
	Set objFSO = Nothing
	Set objTextFile = Nothing
End Sub
After that set in Auto script you can easily use this

Code: Select all

Include("C:\functions.vbs")
WriteLog "LOG written from external Script!"
Functions.vbs looks like this:

Code: Select all

Sub WriteLog(strMessage)
	Const FOR_APPENDING = 8
	strFileName = "C:\test.txt"
	Set objFS = CreateObject("Scripting.FileSystemObject")
	If objFS.FileExists(strFileName) Then
		Set oFile = objFS.OpenTextFile(strFileName, FOR_APPENDING)
	Else
		Set oFile = objFS.CreateTextFile(strFileName)
	End If
	oFile.WriteLine strMessage
End Sub
Hope I make sense?

Regarding Menu Options see https://www.mediamonkey.com/wiki/ISDBUI ... Compendium and https://www.mediamonkey.com/wiki/SDBUI

In last.fm plugin, DLL access/query for SDBApplication object and use saved objects and MM.ini to parse settings and data to/from MMUI and internal DLL features. This approach can be used for any other external script/API, but for portable you need to parse to external script because MM COM SDBApplication is not regisetred in OS and object pointed needs to be parsed from running MM application not queried outside.

May I ask why are you making MM4 script when MM5 is already out and your work can be far more useful if added to MM5 (please do not get me wrong, but user base of MM5 will only grow)?
May I wonder
Best regards,
Peke
MediaMonkey Team lead QA/Tech Support guru
Admin of Free MediaMonkey addon Site HappyMonkeying
Image
Image
Image
How to attach PICTURE/SCREENSHOTS to forum posts
pokeefe0001
Posts: 97
Joined: Thu Oct 11, 2018 4:48 pm
Location: USA, Pacific Northwest

Re: Any way to execute a type=0 script that isn't in scritps.ini?

Post by pokeefe0001 »

Peke wrote: Wed Aug 04, 2021 5:28 pm ...
May I ask why are you making MM4 script when MM5 is already out and your work can be far more useful if added to MM5 (please do not get me wrong, but user base of MM5 will only grow)?
May I wonder
I thought I'd address that last question first before addressing your suggestions (which I thank you for).

Basically, I don't know MediaMonkey and I don't know VBS, JavaScript, much HTML, or any flavor of object-oriented programming. However, I find myself partly responsible getting an old MediaMonkey installation ready for use by a group of highly non-technical elderly folks that haven't seen MediaMonkey (or each other) for 18 months. This has to be ready in 2 more days, and has to look and feel as much as possible like it did 18 months ago.

18 months ago it was MM 2.5 running on 3 ancient laptops, maintained by a person using homegrown Access tools to keep the 3 implementations in sync. But he is getting out of that role. I discovered I could MM 4.1 to look and act almost identical to the old MM 2.5 implementation. And the cloning of the implementations is trivial with simple Windows copy utilities (either File Explorer or Robocopy) followed by execution of the MM script UpdateLocationOfFiles.

I have no idea whether the same can be said for MM 5. All the hype has been on how much it has changed, not on how similar it is to past versions. And I have no idea if UpdateLocationOfFiles has been rewritten in JavaScript (or has been replaced with a different script).

So back to the topic at hand. I need to execute UpdateLocationOfFiles on multiple laptops at least once a week, but I really don't want it accidentally executed by our typical MM user. We do have those users execute some scripts so I really want UpdateLocationOfFiles (a type=0 script) to not show in the list of scripts.

I'll cope with looking into MM 5 when I don't have a looming deadline.

Your idea of inserting UpdateLocationOfFiles into my invoking script may be the way I have to go, but it is a massive script - 35KB in compressed format - all unnecessary blanks removed. I'm uncomfortable with doing anything other than just executing it.

I think I'm proving myself wrong, but I thought this should be a fairly simple process - having a menu item execute a script that did not create the menu item. It maybe is not so straightforward.

Some time after posting my latest question I found SDB.ScriptsPath. It has an "s" that yours does not. Are they two different functions? Anyway, I a simple test. I created a trivial script

Code: Select all

Sub ShowTestMsg()
Dim res
res = SDB.MessageBox( SDB.Localize("This is a test"), mtError, Array(mbOk))
End Sub
and named it ShowTestMsg.vbs. It works fine as a Type=0 script.

I then created an Auto script to create a menu item:

Code: Select all

Sub OnStartup
    Dim FullPath
    FullPath=SDB.ScriptsPath & "ShowTestMsg.vbs"
    With SDB.UI.AddMenuItem(SDB.UI.Menu_File, 1, 3)
        .Caption="Show a test message"
        .UseScript=FullPath
        .OnClickFunc="ShowTestMsg"
    End With
End Sub
The menu item is created, but when I click on it I get an error popup stating:
Error happened during script execution: OLE error 800A01C2
Any idea what that is about? A web search turned up both a number of arguments error and an attempt to set an object with a string.
MMV4 (1919) Portable
MMW5 (2606) Portable
Multiple Win11 x64 21H2
Multiple Win7 x32, unknown builds
Peke
Posts: 17446
Joined: Tue Jun 10, 2003 7:21 pm
Location: Earth
Contact:

Re: Any way to execute a type=0 script that isn't in scritps.ini?

Post by Peke »

Hi,
SDB is not initialized in your external Script.

Here is the code you should try:

Code: Select all

Sub OnStartup
    With SDB.UI.AddMenuItem(SDB.UI.Menu_File, 1, 3)
        .Caption="Show a test message"
        .UseScript=Script.ScriptPath
        .OnClickFunc="ShowTestMsg"
    End With
End Sub

Sub includeFile(fSpec)
    With CreateObject("Scripting.FileSystemObject")
       executeGlobal .openTextFile(fSpec).readAll()
    End With
End Sub

includeFile(SDB.ScriptsPath & "ShowTestMsg.vbs")
Best regards,
Peke
MediaMonkey Team lead QA/Tech Support guru
Admin of Free MediaMonkey addon Site HappyMonkeying
Image
Image
Image
How to attach PICTURE/SCREENSHOTS to forum posts
pokeefe0001
Posts: 97
Joined: Thu Oct 11, 2018 4:48 pm
Location: USA, Pacific Northwest

Re: Any way to execute a type=0 script that isn't in scritps.ini?

Post by pokeefe0001 »

I'm probably about to show my ignorance, but ...

Code: Select all

.UseScript=Script.ScriptPath
.OnClickFunc="ShowTestMsg"
implies that the ShowTestMsg is contained withing this Auto script. Yes? So the IncludeFile subroutine pulls the ShowTestMsg script into this script?

But IncludeFile is not in the OnStartup subroutine. How/when does the IncludeFile get invoked?
MMV4 (1919) Portable
MMW5 (2606) Portable
Multiple Win11 x64 21H2
Multiple Win7 x32, unknown builds
Peke
Posts: 17446
Joined: Tue Jun 10, 2003 7:21 pm
Location: Earth
Contact:

Re: Any way to execute a type=0 script that isn't in scritps.ini?

Post by Peke »

Hi,
I can't test it myself for next few days, but does it work?

MM loads whole script that loads ShowTestMsg.VBS and add it to This file.
Best regards,
Peke
MediaMonkey Team lead QA/Tech Support guru
Admin of Free MediaMonkey addon Site HappyMonkeying
Image
Image
Image
How to attach PICTURE/SCREENSHOTS to forum posts
pokeefe0001
Posts: 97
Joined: Thu Oct 11, 2018 4:48 pm
Location: USA, Pacific Northwest

Re: Any way to execute a type=0 script that isn't in scritps.ini?

Post by pokeefe0001 »

I got OLE error 800A01C2 again.
I'll go back and look at the other samples you showed earlier and see what I'm missing, but probably not today.

I don't need this working immediately, but I really would like to keep UpdateLocationOfFiles out of the list of scripts that the MM users use.
MMV4 (1919) Portable
MMW5 (2606) Portable
Multiple Win11 x64 21H2
Multiple Win7 x32, unknown builds
pokeefe0001
Posts: 97
Joined: Thu Oct 11, 2018 4:48 pm
Location: USA, Pacific Northwest

Re: Any way to execute a type=0 script that isn't in scritps.ini?

Post by pokeefe0001 »

I had other stuff I had to do for a few days, but I'm back testing this and I'm getting nowhere. I've finally determined that my problem, or at least one of them, has nothing to do with finding, loading, and executing the "external" script file. It has something to do with the menu item I've added. I've now got an Auto script that adds a menu item which does absolutely nothing:

Code: Select all

Sub OnStartup

    With SDB.UI.AddMenuItem(SDB.UI.Menu_File, 1, 3)
        .Caption="Show a test message " 
        .UseScript=Script.ScriptPath
        .OnClickFunc="InnerInvocation"
    End With
End Sub

Sub InnerInvocation

End Sub
The menu item gets added, but when selected I get the OLE error 800A01C2 error.

Update:
I just discovered that the invoked subroutine apparently needs an argument. What does MM pass it?
MMV4 (1919) Portable
MMW5 (2606) Portable
Multiple Win11 x64 21H2
Multiple Win7 x32, unknown builds
Peke
Posts: 17446
Joined: Tue Jun 10, 2003 7:21 pm
Location: Earth
Contact:

Re: Any way to execute a type=0 script that isn't in scritps.ini?

Post by Peke »

Hi,
It is just Syntax, I think pointer to object, but you do not need to use it, so you can just add ()

http://www.csidata.com/custserv/onlineh ... /vbs14.htm
https://www.guru99.com/vbscript-procedu ... tions.html
Best regards,
Peke
MediaMonkey Team lead QA/Tech Support guru
Admin of Free MediaMonkey addon Site HappyMonkeying
Image
Image
Image
How to attach PICTURE/SCREENSHOTS to forum posts
pokeefe0001
Posts: 97
Joined: Thu Oct 11, 2018 4:48 pm
Location: USA, Pacific Northwest

Re: Any way to execute a type=0 script that isn't in scritps.ini?

Post by pokeefe0001 »

That's what I did. But I find it strange that a Type=0 script invoked from the Scripts menu does not need those parentheses (so I assume does not get passed an argument) but the exact same script invoked via OnClickFunc in an Auto script's AddMenuItem does need the parentheses. Both are subroutines invoked by clicking on a menu item, but there is obviously some different mechanism involved.
MMV4 (1919) Portable
MMW5 (2606) Portable
Multiple Win11 x64 21H2
Multiple Win7 x32, unknown builds
Post Reply