Help with ad-hoc script editor

I'm trying to run a script with a "cmd.RunCommand" inside the ad-hoc script editor.

But I'm having trouble figuring how to make it work.

This is what I did

If I just use
cmd.RunCommand("Help");
as the only line in the script, the ad-hoc script editor tells me that cmd is not defined

On the other hand if I write
function OnClick(clickData)
{
var cmd = clickData.func.command;
cmd.RunCommand("Help");
DOpus.Output("Test 1");
}
nothing is executed / outputed

I saw that the CLI [Directory Opus Manual] (dopus.com) has an example but without cmd

What am I missing?

function OnClick(clickData) is only called for scripts in buttons/menus/hotkeys.

The Ad-Hoc Script Editors runs script code directly, without needing any function and without passing in any details about the lister / file display the script was run from (since it isn't run from one).

See the text at the top of Command [Directory Opus Manual] for how to create a Command object if one isn't already given to you, which is what you need to do in this context.

1 Like

Thanks.

For my use case

var DOpusFactory = DOpus.Create();
var cmd = DOpusFactory.Command();

did the trick.

For reference, the reason you got this error is because you used var to define the variable, which makes it local to the scope it's defined in (i.e. the OnClick() function).