In command mod: how to launch a specific external program depending on the current selected filename

Hi GPSoftware team,

I have the problem below:

I have a list of files in dopus. Among these files, there is a file name "layout.json" and other ".json" files.
I want to create a command in the context menu that, when I select this file, allows to activate a specific program in charge of the processing of this file.

What I have done is this, but it does not seem to work properly.
I created a command regarding the "json" files, for the context menu.

In this command I wrote:

@if: {file}="layout.json"
J:\MSFSLayoutGenerator.exe {f!}

But this does not work properly. This program activates the external program for every "json" file I select and I want it to work only for the "layout.json" file (In case of activation for another "json" file, the external program reacts as an error).

So, how to do this? It seems quite simple but I do not find the right way to do it.

Thanks.

Patrice

For this logic you need a script. Try this command:

function OnInit(initData) {
    initData.name = 'LaunchMSFSLayoutGenerator';
    initData.version = '2023-06-03';
    initData.url = 'https://resource.dopus.com/t/in-command-mod-how-to-launch-a-specific-external-program-depending-on-the-current-selected-filename/44554';
    initData.default_enable = true;
    initData.min_version = '12.0';
}

function OnAddCommands(addCmdData) {
    var cmd = addCmdData.AddCommand();
    cmd.name = 'LaunchMSFSLayoutGenerator';
    cmd.method = 'OnLaunchMSFSLayoutGenerator';
    cmd.hide = false;
    cmd.icon = 'script';
}

function OnLaunchMSFSLayoutGenerator(scriptCmdData) {
    var cmd = scriptCmdData.func.command;
    var tab = scriptCmdData.func.sourcetab;
    cmd.deselect = false;
    if (tab.selected_files.count == 0) return;
    var item = tab.selected_files(0);
    if (item.name != 'layout.json') return;
    cmd.RunCommand('J:\\MSFSLayoutGenerator.exe "' + item + '"');
}

CommandLaunchMSFSLayoutGenerator.js.txt (952 Bytes)


https://resource.dopus.com/t/how-to-use-buttons-and-scripts-from-this-forum/3546

1 Like

Hi ixp,
Thank you.
I am not easy with scripts in dopus.
How do I insert this in my context menu command related to json files?
Thanks.
Patrice.

Save CommandLaunchMSFSLayoutGenerator.js.txt from above to

%appdata%\GPSoftware\Directory Opus\Script AddIns

Then add the new command LaunchMSFSLayoutGenerator to a button, hotkey, or context menu from the Commands drop-down.

1 Like

Hi ixp,
It works vey well.
Thank you again for this prompt and efficient solution.
Patrice