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