Please allow to specify whether the command Set NOOP leads to a success or error return code. This could be done with Set NOOP=succeed and Set NOOP=fail. The behavior of just Set NOOP should also be defined and documented in this regard (probably succeed by default).
In JScript, I needed to find out whether anything is selected in the source tab to implement voice commands that either show the context menu for the selection or for the current folder (or deny showing it). But neither clickData.func.sourcetab.stats.selitems nor DOpus.listers.lastactive.activetab.stats.selitems worked in the recycle bin virtual folder; they both returned 0 there. So I hacked this together to find out whether anything is selected via standard commands:
cmd.AddLine("@ifsel");
// Should trigger a success return code (truthy). (The command is a no-op, because the filename
// `nul` is forbidden under Windows, and the command is additive without `DESELECTNOMATCH`.)
cmd.AddLine('Select PATTERN="nul" EXACT');
cmd.AddLine("@ifsel:else");
cmd.AddLine("Set NOOP"); // Should trigger an error return code (falsy).
// cmd.AddLine("Marker"); // Alternative to trigger an error return code.
var hasSelection = Boolean(cmd.Run());
This worked, although strangely only with cmd = DOpus.Create().Command(), and not with cmd = clickData.func.command.
Anyways, even if other bugs involved in this are solved, please make Set NOOP usable for workarounds like this, so one doesn't need to hack even more. It's still a no-op with regard to effects caused inside Opus.
Recycle Bin is handled by the Windows Shell (since it's a special view that looks nothing like the real filenames on disk, and the only actions you can do within it are to restore or completely delete things).
Most Opus commands and scripting support isn't available in that folder, but also wouldn't normally be useful either (your case being an exception where it makes sense to need to query the selection count).
[Edit: Removed a section that I thought I'd already edited out. Info was only partially correct after testing things, and it wasn't important compared to the @ifsel thing.]
The only purpose of Set NOOP is to do nothing at all, which is occasionally useful. It always succeeds at doing nothing.
After looking for a good way to do this, I also realised @ifsel won't work here in commands run via scripts, as none of those details are given to scripts when in Recycle Bin (at least currently).
Can you tell us more about what you're aiming to do? I can think of a few other approaches which should work, but am not sure which would be most suitable, and want to try them myself before sending you down the wrong path.
But I used it for the exact reason that it fails, just like Marker. (Set NOOP=fail would be clear, anyways.)
I have two voice commands (and two extra derived ones which show the respective extended context menu; Talon simulates pressing the menu key for this, possibly while holding Shift):
One for showing the context menu of the selected items. When it was uttered and something was selected, the menu should be shown. When nothing was selected, nothing should be done.
Another one for showing the context menu of the current folder, which always should succeed. I currently deselect everything to accomplish this by running Select NONE. But in the future (or now, if I missed something), I would like to avoid deselecting everything to show the folder's context menu.
I'm now calling cmd.SetSourceTab(clickData.func.command.sourcetab) on DOpus.Create().Command(), which works with my hack, while using clickData.func.command instead doesn't.
Also, in the "This PC" virtual folder, the hack again doesn't work, so I have to run the following after the hack:
if (cmd.sourcetab.stats.selitems > 0) {
hasSelection = true;
}