Help running cmd from script

I want to "modernize" some of my custom buttons with own GUIs, but not good in scripting. So I first used an example script from manual for MP3-encoding, but got error in run.command:

function OnClick(clickData) {
    var Dlg = DOpus.Dlg;
    Dlg.window = clickData.func.sourcetab;
    Dlg.template = "dlg";
    var retVal = Dlg.Show();
    cmd.RunCommand('/dopusdata\User Data\Lame\Lame.exe' +retVal '{filepath$}');
}

"retVal" is choosen compression value, error is

')' erwartet (0x800a03ee)
Parsefehler - Skript abgebrochen

Looks like there's a missing + after retVal.

I see trouble coming from missing quotes, spaces, and unescaped backslashes.

1 Like

Still got an error. Here's the full code (once it will work I am able to rewrite all my buttons on my own :-)):

<resources>
    <resource name="dlg" type="dialog">
       <dialog fontsize="8" height="50" lang="" title="MP3 encoden" width="180">
           <control halign="left" height="8" name="static1" title="Bitte MP3-Qualität auswählen:"
              type="static" width="100" x="42" y="9" />
           <control close="1" default="yes" height="14" name="-b 320" title="320 kbps"
              type="button" width="50" x="9" y="30" />
           <control close="2" height="14" name="-b 160" title="160 kbps" type="button"
              width="50" x="66" y="30" />
           <control close="3" height="14" name="-b 128" title="128 kbps" type="button"
              width="50" x="122" y="30" />
       </dialog>
    </resource>
</resources>
function OnClick(clickData) {
    var Dlg = DOpus.Dlg;
    Dlg.window = clickData.func.sourcetab;
    Dlg.template = "dlg";
    var retVal = Dlg.Show();
    cmd.RunCommand('/dopusdata\User Data\Lame\Lame.exe' + retVal + '{filepath$}');
}

You'll find bugs much more quickly and avoid side effects, if you split the command like this:

cmd.RunCommand('Set UTILITY=otherlog');
DOpus.ClearOutput();

var cmdLine = 'GO PATH="' + srcPath + '"';
DOpus.Output(cmdLine);
// cmd.RunCommand(cmdLine);
2 Likes

I still don't get the exe to be executed (not defined):

cmd.RunCommand('"//dopusdata\\User Data\\Lame\\Lame.exe"');

In JScript, the / shouldn’t be doubled, only the \.

Thanks, in default jscript button it works, in my cmd still got error "cmd not defined"? I don't get it.

Something like

var cmd = clickData.func.command;

is missing.

Thank you very much, lxp, it works. As said, I am no developer.

Now I just need to get variable "value" implemented, what do I wrong here?

cmd.RunCommand('"/dopusdata\\User Data\\Lame\\Lame.exe"' +value+ '{filepath$}');

Probably missing spaces around value.

Maybe post the button as xml, so we have to guess less.

Attached, thanks.

And at least I need one example how to set button close to a value (here: close 1 = -b 320, close 2 = -b 160, and so on).

<?xml version="1.0"?>
<button backcol="none" display="icon" textcol="none">
	<label>_SC_Testbutton</label>
	<icon1>#usercommand</icon1>
	<function type="script">
		<instruction>@script JScript</instruction>
		<instruction>function OnClick(clickData) {</instruction>
		<instruction>    var Dlg = DOpus.Dlg;</instruction>
		<instruction>    Dlg.window = clickData.func.sourcetab;</instruction>
		<instruction>    Dlg.template = &quot;mydlg&quot;;</instruction>
		<instruction>    var retVal = Dlg.Show();</instruction>
		<instruction>	var cmd = clickData.func.command;</instruction>
		<instruction>	cmd.RunCommand(&apos;&quot;/dopusdata\\User Data\\Lame\\Lame.exe&quot;&apos; +&quot;retVal&quot; + &apos;{filepath$}&apos;);</instruction>
		<instruction>}</instruction>
		<instruction> </instruction>
		<instruction />
		<instruction />
		<instruction>==SCRIPT RESOURCES</instruction>
		<instruction>&lt;resources&gt;</instruction>
		<instruction>	&lt;resource name=&quot;mydlg&quot; type=&quot;dialog&quot;&gt;</instruction>
		<instruction>		&lt;dialog fontsize=&quot;8&quot; height=&quot;123&quot; lang=&quot;german&quot; title=&quot;MP3 encoden&quot; width=&quot;142&quot;&gt;</instruction>
		<instruction>			&lt;control halign=&quot;left&quot; height=&quot;8&quot; name=&quot;static1&quot; title=&quot;Bitte Qualität auswählen:&quot; type=&quot;static&quot; valign=&quot;top&quot; width=&quot;83&quot; x=&quot;33&quot; y=&quot;9&quot; /&gt;</instruction>
		<instruction>			&lt;control close=&quot;1&quot; height=&quot;14&quot; name=&quot;button1&quot; title=&quot;CBR 320 kbps (Beste)&quot; type=&quot;button&quot; width=&quot;92&quot; x=&quot;28&quot; y=&quot;29&quot; /&gt;</instruction>
		<instruction>			&lt;control close=&quot;2&quot; height=&quot;14&quot; name=&quot;button2&quot; title=&quot;CBR 160 kbps (Medium)&quot; type=&quot;button&quot; width=&quot;92&quot; x=&quot;28&quot; y=&quot;47&quot; /&gt;</instruction>
		<instruction>			&lt;control close=&quot;3&quot; height=&quot;14&quot; name=&quot;button3&quot; title=&quot;CBR 128 kbps (Web/Mail)&quot; type=&quot;button&quot; width=&quot;92&quot; x=&quot;28&quot; y=&quot;65&quot; /&gt;</instruction>
		<instruction>			&lt;control close=&quot;4&quot; height=&quot;14&quot; name=&quot;button4&quot; title=&quot;VBR ~220 kbps (Beste)&quot; type=&quot;button&quot; width=&quot;92&quot; x=&quot;28&quot; y=&quot;83&quot; /&gt;</instruction>
		<instruction>			&lt;control close=&quot;5&quot; height=&quot;14&quot; name=&quot;button5&quot; title=&quot;VBR ~165 kbps (Medium)&quot; type=&quot;button&quot; width=&quot;92&quot; x=&quot;28&quot; y=&quot;101&quot; /&gt;</instruction>
		<instruction>		&lt;/dialog&gt;</instruction>
		<instruction>	&lt;/resource&gt;</instruction>
		<instruction>&lt;/resources&gt;</instruction>
	</function>
</button>

Here you go.

function OnClick(clickData) {
    var cmd = clickData.func.command;
    var dlg = clickData.func.Dlg();
    dlg.window = clickData.func.sourcetab;
    dlg.template = 'mydlg';
    
    var retVal = dlg.Show();
    if (retVal == 1) var encVal = '-b 320';
    if (retVal == 2) var encVal = '-b 160';
    if (retVal == 3) var encVal = '-b 128';
    if (retVal == 4) var encVal = '-V ...';
    if (retVal == 5) var encVal = '-V ...';
    
    var cmdLine = ('"/dopusdata\\User Data\\Lame\\Lame.exe" ' + encVal + ' "{filepath$}"');
    DOpus.Output(cmdLine);
    cmd.RunCommand('dopusrt /argsmsgbox ' + cmdLine);
    // cmd.RunCommand(cmdLine);
}

Big thanks, lxp. It works and with this example I can create a nicer GUI for all my other audio-buttons! :+1:

One last question, if I add a radio button, how to get its value?

Reading Dialog Control Values in the manual shows how to get a value from a control.

1 Like

The manual explains return value for button (close value), but there's no such value for radiobutton.

It explains both. The control.value property tells you if a radiobutton is on or off.

1 Like

Ah, ok. Sorry for my ignorance in scripting.

Hi Sasa I have interest in your audio buttons. Can you tell me what does this button does?