Can't open Utility Pane from CLI when calling script add-in

Hello.
I have a script add-in that opens the Utility Pane.

var cmd = scriptCmdData.func.command;
cmd.RunCommand("Set UTILITY=OtherLog");

When I call this script from a button, the Utility Pane opens, but when run from the DOpus Command Line Interpreter, the Utility Pane does not open.

What exactly are you running from the CLI? A script command (e.g. just the name of the command)? Or the actual script code itself?

The name of the script command.
Also if I add this to the add-in script:
cmd.RunCommand('@confirm:hello');
The @confirm dialog displays as expected.

I tried a minimal script command that simply runs that code and nothing else, and it works fine from the CLI as well as from a button. So it maybe something else the script is doing. Could you post the whole script?

Try it with more than one lister open.
I just tried with only one lister and it worked right.
All I changed from the code created automatically by the "Create New Script" dialog was I added the var and the RunCommand.
Here's the code:

function OnInit(initData)
{
	initData.name = "defScript";
	initData.version = "1.0";
	initData.copyright = "(c) 2020 will";
//	initData.url = "https://resource.dopus.com/viewforum.php?f=35";
	initData.desc = "";
	initData.default_enable = true;
	initData.min_version = "12.0";

	var cmd = initData.AddCommand();
	cmd.name = "defScript";
	cmd.method = "OndefScript";
	cmd.desc = "";
	cmd.label = "defScript";
	cmd.template = "";
	cmd.hide = false;
	cmd.icon = "script";
}


// Implement the defScript command
function OndefScript(scriptCmdData)
{
	var cmd = scriptCmdData.func.command;
	cmd.RunCommand("Set UTILITY=OtherLog");
}

With more than one Lister open it should still work (and does here), but the Lister the command runs in might be unpredictable, since commands launched from the CLI aren't attached to a particular Lister by default.

(I would have expected it to run in whichever Lister was currently the source; and if no Listers are the source the last active one, but I haven't checked).

If you want to test the command against a specific window without setting up a button you can press > in the file display and run the command from the FAYT.

That's odd -- it's not working here. If I open two listers, the Utility Pane does not open in either one.
I just tried it on fresh install of DOpus in a virtual machine -- it doesn't work there. I upgraded the one in the virtual machine from 12.19 to 12.9-beta-4 -- still doesn't work.

If anyone else reads this, could you please try on your machine?

Do any commands work in the CLI for you?

Try Help ABOUT as an example.

If no commands work, you probably have the CLI in script mode, not command mode. (Turn off the Script Interpreter checkbox at the bottom left of the CLI.)

Yeah -- Help ABOUT works (even with multiple listers open). And my original code works -- as long as there's only one lister.
I think we can skip the "script add-in" part, because I just tested Set UTILITY=OtherLog directly in the CLI: it only works if there is only one lister.
I also tried opening the Utility Pane to Find mode before running Set -- if there's more than one lister it does not change to OtherLogs. With one lister -- it works.

Here's what I see. It seems to work correctly, and targets the Source lister (if there is one, otherwise the last active window, I think):

Ah I think we're on to something. It DOES work if one of my listers is in single-pane mode.
With at least one single-pane lister, the Utility Pane always opens in that lister.
If they are all dual-pane, the Utility Pane does not open.

1 Like

I can confirm what @Hoosh is seeing here. Although, if I only have 1 lister open (in dual pane) the script works. If I have two or more in dual pane mode, the script does nothing and if I have multiple listers with one being single pane then the script works and opens in that lister regardless of which was last active.

We have a change coming in the next beta that will make the Command (non-scripting) mode of the CLI stick to the lister that launched it (if there is one), and if that doesn't exist or is closed then it'll look for another window and include dual-display windows now.

This won't change what happens with Scripting mode, as it's how scripts are supposed to work and how they work in other contexts as well. But you can use code like this in a CLI script to do something similar:

var cmd = DOpus.Create.Command();
cmd.SetSourceTab(DOpus.listers.lastactive.activetab);
cmd.RunCommand("Set UTILITY=Find,Toggle");

(If you create a blank scripting Command object, you need to tell it which lister/tab to work on, or it won't know. They will guess in some cases, but the guesses shouldn't be relied on and are very conservative; if a window is needed and there are multiple potential candidates then it will not run at all to avoid choosing the wrong one. Choosing the wrong one could mean running destructive commands on the wrong files/folder, which would be catastrophic. The pre-made objects given to scripts that run in buttons/hotkeys are already set up and don't need that, but if you create a new one then it has to be set up. The CLI doesn't pass any pre-made objects to the scripts it runs.)

2 Likes