[SOLVED] Code snippet for "open external program"

Post a reply

Smilies
:D :) :( :o :-? 8) :lol: :x :P :oops: :cry: :evil: :roll: :wink:

BBCode is ON
[img] is ON
[url] is ON
Smilies are ON

Topic review
   

Expand view Topic review: [SOLVED] Code snippet for "open external program"

Re: Code snippet for "open external program"

by Andre_H » Sun Aug 22, 2021 7:43 am

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

Re: Code snippet for "open external program"

by drakinite » Sat Aug 21, 2021 10:16 pm

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!)

Re: Code snippet for "open external program"

by Andre_H » Wed Aug 18, 2021 11:48 am

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:

Re: Code snippet for "open external program"

by Andre_H » Wed Aug 18, 2021 2:40 am

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.

Re: Code snippet for "open external program"

by TIV73 » Tue Aug 17, 2021 5:03 pm

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')

Re: Code snippet for "open external program"

by Andre_H » Tue Aug 17, 2021 5:58 am

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!

Re: Code snippet for "open external program"

by drakinite » Sat Aug 14, 2021 2:40 pm

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.

Re: Code snippet for "open external program"

by Erwin Hanzl » Sat Aug 14, 2021 1:32 pm

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.

[SOLVED] Code snippet for "open external program"

by Andre_H » Thu Aug 12, 2021 4:56 am

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.

Top