[SOLVED] Code snippet for "open external program"

Get help for different MediaMonkey v5 / v2024 Addons.

Moderators: jiri, drakinite, Addon Administrators

Andre_H
Posts: 446
Joined: Thu Jan 21, 2021 2:04 pm
Location: Germany

[SOLVED] Code snippet for "open external program"

Post by Andre_H »

Hi guys,

Can someone provide me with a code example where an external program is opened from the track context?
(E.g. "Find more" => "Open in Explorer"), I can't find the part in the source code.

I would like to write a little addon that will open the folder of a selected track in MP3Tag.
Last edited by Andre_H on Wed Aug 18, 2021 6:09 pm, edited 1 time in total.
- my 24/7 media server | MMW 2024.0.0.3038 (non-portable, shared DB & files, only essential addons) | Windows 2016
- my desktop app | MMW 2024.0.0.3038 (portable, shared DB & files) | Windows 11
- my mobile app | MMA Pro 2.0.0.1175 on several Android 10, 11, 12 devices | WiFi Sync

- MP3Tag | MP3Diags | MP3DirectCut | IrfanView
Erwin Hanzl
Posts: 1190
Joined: Tue Jun 13, 2017 8:47 am
Location: Vienna

Re: Code snippet for "open external program"

Post by Erwin Hanzl »

Hallo Andre,

da gibt es ein Addon, allerdings für MM4.
Nennt sich "External Tools 1.4." siehe https://www.mediamonkey.com/addons/brow ... rnaltools/

Vielleicht kannst du daraus Ideen für MM5 ableiten.
MMW 4.1.31.1919 Gold-Standardinstallation
drakinite
Posts: 988
Joined: Tue May 12, 2020 10:06 am
Contact:

Re: Code snippet for "open external program"

Post by drakinite »

It's in actions.openExplorer. :)
navigationHandlers['explorerFolder'] is the function that it uses, which in turn uses app.utils.openExplorerFolder to open a file in File Explorer.
Image
Data scientist, web programmer, part-time MediaMonkey developer, full-time MediaMonkey enthusiast
I uploaded many addons to MM's addon page, but not all of those were created by me. "By drakinite, Submitted by drakinite" means I made it on my own time. "By Ventis Media, Inc., Submitted by drakinite" means it may have been made by me or another MediaMonkey developer, so instead of crediting/thanking me, please thank the team. You can still ask me for support on any of our addons.
Andre_H
Posts: 446
Joined: Thu Jan 21, 2021 2:04 pm
Location: Germany

Re: Code snippet for "open external program"

Post by Andre_H »

Hi drakinite,

you know that you are talking to a total beginner about JS ... ;-) ok, i found this in "actions.js" ...

Code: Select all

        openExplorer: {
            title: function () {
                return _('Open in Explorer');
            },
            icon: 'openFile',
            execute: function () {
                navUtils.getFocusedFolder().then(function (initPath) {
                    var dummyTrack = app.utils.createEmptyTrack();
                    dummyTrack.dontNotify = true;
                    dummyTrack.path = initPath;
                    navigationHandlers['explorerFolder'].navigate(dummyTrack);
                });
            }
        },
... guess, it's the right one. I was hoping to find some kind of "open %windir%\explorer.exe" syntax that I could simply adapt to an "mp3tag.exe / parameters".

So i think "explorerFolder" should be that one, but i don't find any "navigationHandlers['explorerFolder']" - routine.

can you give me some more hints?

thanks!
- my 24/7 media server | MMW 2024.0.0.3038 (non-portable, shared DB & files, only essential addons) | Windows 2016
- my desktop app | MMW 2024.0.0.3038 (portable, shared DB & files) | Windows 11
- my mobile app | MMA Pro 2.0.0.1175 on several Android 10, 11, 12 devices | WiFi Sync

- MP3Tag | MP3Diags | MP3DirectCut | IrfanView
TIV73
Posts: 246
Joined: Sat Nov 12, 2011 1:31 pm

Re: Code snippet for "open external program"

Post by TIV73 »

What is happening in that snippet is that you are opening the navigationHandler of type explorerFolder. A navigation handler is just that, a handler for a certain type of navigation, e.g. opening a certain album, or a playlist or something. The explorerFolder handler opens the file explorer at whatever path you point it to.

You can't just give it a folder name, it expects a track object, that's why the lines above the handler do. The snippet just creates an empty dummy track object, suppresses some notifications, sets the filepath of the dummy track to whatever has been provided in the initPath parameter and passes the object to the explorerFolder handler, which then opens an explorer window at the file path. Issue is that explorerFolder does just this one thing. You can't tell it to open a file or start an application.

What you likely want is utils.shellExecute which accepts two arguments for the command to execute and additional parameters:

Code: Select all

app.utils.shellExecute('explorer','C:\\temp')
Andre_H
Posts: 446
Joined: Thu Jan 21, 2021 2:04 pm
Location: Germany

Re: Code snippet for "open external program"

Post by Andre_H »

Hi & thank you thanks for the code sample, which is very helpful.

I will test this in the coming days and give you feedback here.
- my 24/7 media server | MMW 2024.0.0.3038 (non-portable, shared DB & files, only essential addons) | Windows 2016
- my desktop app | MMW 2024.0.0.3038 (portable, shared DB & files) | Windows 11
- my mobile app | MMA Pro 2.0.0.1175 on several Android 10, 11, 12 devices | WiFi Sync

- MP3Tag | MP3Diags | MP3DirectCut | IrfanView
Andre_H
Posts: 446
Joined: Thu Jan 21, 2021 2:04 pm
Location: Germany

Re: Code snippet for "open external program"

Post by Andre_H »

EDIT: Got it ...

Code: Select all

//* open folder of selected track in MP3Tag.*//

actions.openMP3Tag = {
    title: _('Oeffne Track-Ordner in MP3Tag ...'),
    icon: 'openMP3Tag',
    disabled: uitools.notMediaListSelected,
    visible: window.uitools.getCanEdit,
    execute: async function () {	
	var list = await uitools.getSelectedTracklist().whenLoaded();
        
	if (list.count === 0) {
            return;
        }

        list.forEach(function(itm) {
        	var AppPath = "E:\\# Tools #\\Mp3Tag\\MP3Tag.exe";
		var AppParameters = '/fp:"' + itm.path + '"'
		app.utils.shellExecute(AppPath, AppParameters)	
        });       
    }
}

window._menuItems.editTags.action.submenu.push({
        action: actions.openMP3Tag,
        order: 100,
        grouporder: 10
});
... works.

Thanks @ all for helping me to get this running.

:wink:
- my 24/7 media server | MMW 2024.0.0.3038 (non-portable, shared DB & files, only essential addons) | Windows 2016
- my desktop app | MMW 2024.0.0.3038 (portable, shared DB & files) | Windows 11
- my mobile app | MMA Pro 2.0.0.1175 on several Android 10, 11, 12 devices | WiFi Sync

- MP3Tag | MP3Diags | MP3DirectCut | IrfanView
drakinite
Posts: 988
Joined: Tue May 12, 2020 10:06 am
Contact:

Re: Code snippet for "open external program"

Post by drakinite »

Andre_H wrote: Tue Aug 17, 2021 5:58 am Hi drakinite,

you know that you are talking to a total beginner about JS ... ;-)
I'm sorry, I forgot that fact :sweat_smile:
Glad that you got it in the end (Many thanks to TIV73 for helping out while I was away!)
Image
Data scientist, web programmer, part-time MediaMonkey developer, full-time MediaMonkey enthusiast
I uploaded many addons to MM's addon page, but not all of those were created by me. "By drakinite, Submitted by drakinite" means I made it on my own time. "By Ventis Media, Inc., Submitted by drakinite" means it may have been made by me or another MediaMonkey developer, so instead of crediting/thanking me, please thank the team. You can still ask me for support on any of our addons.
Andre_H
Posts: 446
Joined: Thu Jan 21, 2021 2:04 pm
Location: Germany

Re: Code snippet for "open external program"

Post by Andre_H »

drakinite wrote: Sat Aug 21, 2021 10:16 pm I'm sorry, I forgot that fact :sweat_smile:
I am generously willing to forgive you (this time).

:D
- my 24/7 media server | MMW 2024.0.0.3038 (non-portable, shared DB & files, only essential addons) | Windows 2016
- my desktop app | MMW 2024.0.0.3038 (portable, shared DB & files) | Windows 11
- my mobile app | MMA Pro 2.0.0.1175 on several Android 10, 11, 12 devices | WiFi Sync

- MP3Tag | MP3Diags | MP3DirectCut | IrfanView
Post Reply