Usage of @set/@if:$var/@if:else

I think I must be doing something wrong here, but trying to follow examples in DOpus Help in writing a custom batch command to convert a selected PDF to PNG using MuPDF:mutool, whether or not the PDF requires a password. My code so far:

@filesonly
@nofilenamequoting
@leavedoswindowopen
@set pwd={dlgpassword|Password?\n(Press CANCEL if none)}
@if:$pwd
"C:\Portable Apps\MuPDF\mutool" draw -p $pwd -o "{file$|noext} - %%d.png" -r 300 -c rgb "{file$}"
@if:else
"C:\Portable Apps\MuPDF\mutool" draw -o "{file$|noext} - %%d.png" -r 300 -c rgb "{file$}"

I figured that:

  1. If I enter a password in the dialog and select the OK button, then $pwd would be set and my command line immediately following @if:$pwd would execute;

  2. If I select the CANCEL button in the password dialog, then $pwd would NOT be set, and my command line immediately following @if:else would execute

…But neither command line executes. A command prompt window doesn’t even get opened.

If I scale back my code to just this and use it on a password-protect PDF:

@filesonly
@nofilenamequoting
@leavedoswindowopen
@set pwd={dlgpassword|Password?\n(Press CANCEL if none)}
"C:\Portable Apps\MuPDF\mutool" draw -p $pwd -o "{file$|noext} - %%d.png" -r 300 -c rgb "{file$}"

…I get error message cannot authenticate password from mutool. Also tried quoting schemes for my @set invocation:

@set "pwd={dlgpassword|Password?\n(Press CANCEL if none)}"
@set pwd="{dlgpassword|Password?\n(Press CANCEL if none)}"

Same error message received. But this works, on password-protected files:

@filesonly
@nofilenamequoting
@leavedoswindowopen
"C:\Portable Apps\MuPDF\mutool" draw -p {dlgpassword|Password?\n(Press CANCEL if none)} -o "{file$|noext} - %%d.png" -r 300 -c rgb "{file$}"

And this works, on NON-password-protected files:

@filesonly
@nofilenamequoting
@leavedoswindowopen
"C:\Portable Apps\MuPDF\mutool" draw -o "{file$|noext} - %%d.png" -r 300 -c rgb "{file$}"

Am I doing something wrong with @set and @if?

If you cancel the {dlgpassword} prompt, the button will abort. Nothing else will run after that point. If you want different behavior, you need to use scripting for that.

You also can't mix Opus conditions / flow control with external commands in DOS Batch buttons, since DOS has to ultimately run all external the parts, which means any sections that run external commands get split out into separate batch files for DOS to run.

Using scripting instead of DOS Batch is better if you want to do that kind of thing.

(Alternatively, you can do all the flow control using DOS Batch things, but DOS Batch is best left behind these days.)

I see. Well, in that case, it would be nice if it was clear which command modifiers can’t be mixed with DOS batch when reading the help, since many of them CAN be mixed.

Technically, they can be mixed, but you have to be careful. The manual could/should go into detail about this, I agree.

As a general rule, avoid DOS Batch entirely, as it's archaic and always was garbage, even back in the 80s & 90s. :slight_smile: Although it can still be useful when running several command-line tools in succession if you want them all to output to the same command prompt window.