GP SoftwareTwitter
Opus FAQsManualCommandsObjects

Yes/no Dialogue with variables in CMD

In Windows batch scripting we have something called GOTO
What would be the equivalent in Dopus standard function?

Basically I want to use {dlgchoose} to aks the user a yes or no question e.g
{dlgchoose|Does this file contain audio?|Yes=___+NO=___}

If the user chooses yes or no I want to jump to somewhere in the function.

I hope this makes sense. It is a bit hard to explain in a second language.

Use Scripting.

Thanks Leo. I started learning some VBScript and I have managed to produce the following VBScript using Select Case

dlg = MsgBox ("Does this file contain audio?", vbYesNo, "Audio?")

Select Case dlg
Case vbYes
	' Open cmd and echo "affirmative"
Case vbNo
    ' Open cmd and echo "negative"
End Select

I am quite stuck on what to do next though. Basically I would like to pass variables to a CMD Window. I want the script to open a Windows CMD window and echo "affirmative" if the user chose yes, and echo "negative" if the user chose no.

Is this possible at all? I have searched a lot for a solution without finding any good resources...

Opus has its own Dialog object which you probably want to use instead of MsgBox, so that you can set the lister as the parent window and avoid the MsgBox going behind the lister, and so on.

If your script is run via a toolbar button or hotkey, you'll be passed a Dialog object which is already set up to use the lister that launched it as its parent window.

That Dialog object has helpers for quickly creating simple dialogs with a message, buttons and optional extras like checkboxes, a drop-down or a list.

Scripts can also create more complex dialogs, with a full-blown dialog editor: Script Dialogs.


Back to your question: Do you really want to use a CMD window, or do you just want a way to output some text to debug the script?

Use DOpus.Output if you just want to output some text, and then display the Script Log to see it.

I did read into the built in dialogues. I am not sure why I went for a MsgBox instead. I realize it makes more sense to use Dopus' dialogue boxes.

The reason why I want to pass variables to CMD is because I use a lot of command line tools such as JpegOptim, ffmpeg, mkvmerge and so on. What I want to achieve (ultimately) is to use DOpus' message boxes to pass variables to a command line an then run a script based on the user input.

I will give a very basic example:
(I know it is possible to use {dlgchoose} for this)

For example, in the following command -p means to preserve timestamps in an image file.
It would be nice if Dopus could prompt a dialogue box asking:
"Do you want to preserve timestamps?"
"Yes" / "No"
And then add -p if the user clicks on "yes" and enters nothing if the user clicks on "no".

jpegoptim -v -p -t -m60 -dC:\Users\Nine\Desktop\new image.jpg

There are lots of ways you can do it, (e.g. running cmd.exe /k ... or cmd.exe /c ... from the script and passing it a command line to run), but the best is probably to use Opus's Command object.

You can set the object to MS-DOS Batch mode (cmd.SetType("msdos")), add one or more lines to it (including a pause command it you want the window to stay open after it finishes) and then run them using that.

As with the Dialog object, you'll be given one that is already set up if you're called from a script or a button. (You might want to call ClearFiles on it before using it, if you don't want the file selection to be passed to it and used when building the final command lines to be run. Or you might not want to, if you want to use the selected files in the commands.)

Thanks a bunch for trying to teach me something. This is getting quite complicated for me. I really try to keep up here, but I am afraid I am not sure what you are saying. An example would be very useful...

What really confuses me is how I can utilise script dialogues to pass information to CMD.

I know now that I can do for example cmd.exe /k {f!} ffmpeg but how can I use a script dialog to pass either -p or nothing depending on yes/no question?

Also, I never got cmd.SetType("msdos") to work. I just get an error saying "Windows cannot find 'cmd.SetType("msdos")'"

I realise I am asking a lot here. I would really like to learn more, but I feel like there are not enough examples to go on. The Dopus online help is great but it is also very general.

Here's an example script that shows a dialog with a "Preserve timestamps" checkbox, and then runs a command with the -p flag added if the checkbox was turned on. Currently it just prints a command line to a DOS prompt - you'll need to take out the echo command and set the path of the jpegoptim command as necessary (as well as add any other options you want).

If you select one or more files and click the button, you'll see the command line printed once for each selected file.

Dialog Example.dcf (2.5 KB)

(see How to use buttons and scripts from this forum for instructions on how to use the .dcf file).