Need help creating a dialog for an MS-DOS script

From what I understand, in order to create a dialog, I must use VBScript. Therefore, I must convert my existing MS-DOS script to a VBScript. Moreover, VBScript's Resources let's me create a dialog in a nice drag-drop GUI which is very attractive.

My problem is, I simply can't find good documentation on how to run a command-line exe while using Dopus variables like {file$} or {filepath|noext}

Here is my script:

@disablenosel
@runmode:min

X:\ProgramFiles\_ffmpeg\ffmpeg-4.3.2-2021-02-27-full_build\bin\ffmpeg.exe -i {file$} -c:a libvorbis -qscale:a 6 "{filepath|noext}.ogg"

REM @leavedoswindowopen

I would like to start with a simple quality selection. Perhaps a dropdown menu that will let me chose Low / Medium / High quality presets. I referenced this, but I think this is going to be limited since script dialog is more flexible and will let me add multiple options... I'd rather learn how to do that because eventually I may want to do things like, select audio track 2 when converting audio from video files. Etc.

  • -qscale:a – audio quality. Range is -1.0 to 10.0, where 10.0 is highest quality. Default is -q:a 3 with a target of ​112kbps. The formula 16×(q+4) is used below 4, 32×q is used below 8, and 64×(q-4) otherwise. Examples: 112=16×(3+4), 160=32×5, 200=32×6.25, 384=64×(10-4).

Any help would be appreciated. :slight_smile:

Thanks,
-Neil

The Command object can be used to run commands from scripts.

If you've added the files you want to the object (AddFiles method), codes like {file$} will work the same as in an normal button. Alternatively, you can generate the command lines in script code, inserting the filenames yourself, if you need the extra flexibility, or a mix of the two.

Use the SetModifier method to set the @runmode modifier. For @disablenosel, there's a deselect property on the object you can set to false (although you can also use SetModifier to set that as well).

Use SetType if you need to set the object to MS-DOS mode.

To run a single-line command, you can use RunCommand on its own. Or, to run a multi-line command, use AddLines and then Run. ClearLines removes any existing lines.

Thank you for your help! I wrote a script (I'm sure it's very poorly written).

Result: Convert to Vorbis OGG with Directory Opus - YouTube

Is there a way that I can specify a default value for the Quality control? I tried everything but I gave up.

JScript:

function OnClick(clickData)
{

	cmd = clickData.func.command;
	tab = clickData.func.sourcetab;
	selFiles = new Enumerator(tab.selected)
	firstSelFile = selFiles.item()

	if (firstSelFile != null) {

		cmd.ClearFiles();
		cmd.AddFiles(tab.selected);
	
		cmd.setType("msdos")
		cmd.setModifier('runmode', 'min');
		//cmd.setModifier('leavedoswindowopen');

	    Dlg = DOpus.Dlg;
	    Dlg.window = clickData.func.sourcetab;
	    Dlg.template = "Main"
		
	    Dlg.Show();

		var qLevel = 0;
		var kbps = '0kbps';
		if ( Dlg.Control('Quality').value() == 0 ) {
			qLevel = 0;
			kbps = '64kbps';
		}
		else if ( Dlg.Control('Quality').value() == 1 ) {
			qLevel = 2;
			kbps = '96kbps';
		}
		else if ( Dlg.Control('Quality').value() == 2 ) {
			qLevel = 4;
			kbps = '128kbps';
		}
		else if ( Dlg.Control('Quality').value() == 3 ) {
			qLevel = 6;
			kbps = '192kbps';
		}
		else if ( Dlg.Control('Quality').value() == 4 ) {
			qLevel = 8;
			kbps = '256kbps';
		}
		else {
			qLevel = 10;
			kbps = '384kbps';
		}

		cmdToRun = '"X:\\ProgramFiles\\_ffmpeg\\ffmpeg-4.3.2-2021-02-27-full_build\\bin\\ffmpeg.exe" -i {filepath$} -c:a libvorbis -qscale:a ' + qLevel + ' {filepath|noext}_vorbis_q' + qLevel + '_' + kbps + '.ogg ';


		
		cmd.RunCommand(cmdToRun);
	}
	else {
		DOpus.Output('No files are selected');
	}
	
}

Resources:

<resources>
	<resource name="Main" type="dialog">
		<dialog fontsize="8" height="78" lang="english" resize="yes" standard_buttons="ok,cancel" title="Convert to Vorbis OGG" width="201">
			<control height="8" name="Quality" resize="w" type="combo" width="102" x="66" y="24" default="2">
				<contents>
					<item text="q0 (~64kbps) Very Low" />
					<item text="q2 (~96kbps) Low" />
					<item text="q4 (~128kbps) Medium" />
					<item text="q6 (~192kbps) High" />
					<item text="q8 (~256kbps) Very High" />
					<item text="q10 (~384kbps) Ultra High" />
				</contents>
			</control>
			<control halign="right" height="10" name="static1" title="Quality:" type="static" width="54" x="6" y="26" />
		</dialog>
	</resource>
</resources>

Yes, replace your current Dlg.Show(); line with something this:

    Dlg.Create(); // Dialog is not visible yet.
    // ... Set up controls as needed
    Dlg.Control('Quality').value = 3;
    // ...
    // Dlg.Show(); needed here before Opus 12.22
    Dlg.RunDlg(); // Dialog becomes visible. Won't return until dialog is closed.
1 Like

Worked like a charm! I had to update to the latest version of Dopus. I was on 12.18 beta.

I forgot to make the script behave correctly I click "Cancel". I fixed that by adding:

if (Dlg.result == 0) {
     DOpus.Output('User Cancelled');
}
else {
     cmd.RunCommand(cmdToRun);
}

Final JScript:

function OnClick(clickData)
{

	cmd = clickData.func.command;
	tab = clickData.func.sourcetab;
	selFiles = new Enumerator(tab.selected)
	firstSelFile = selFiles.item()

	if (firstSelFile != null) {

		cmd.ClearFiles();
		cmd.AddFiles(tab.selected);
	
		cmd.setType("msdos")
		cmd.setModifier('runmode', 'min');
		//cmd.setModifier('leavedoswindowopen');

	    Dlg = DOpus.Dlg;
	    Dlg.window = clickData.func.sourcetab;
	    Dlg.template = "Main"

		Dlg.Create(); // Dialog is not visible yet.
		Dlg.Control('Quality').value = 3;
	    //Dlg.Show();
		Dlg.RunDlg(); // Dialog becomes visible. Won't return until dialog is closed

		var qLevel = 0;
		var kbps = '0kbps';
		if ( Dlg.Control('Quality').value() == 0 ) {
			qLevel = 0;
			kbps = '64kbps';
		}
		else if ( Dlg.Control('Quality').value() == 1 ) {
			qLevel = 2;
			kbps = '96kbps';
		}
		else if ( Dlg.Control('Quality').value() == 2 ) {
			qLevel = 4;
			kbps = '128kbps';
		}
		else if ( Dlg.Control('Quality').value() == 3 ) {
			qLevel = 6;
			kbps = '192kbps';
		}
		else if ( Dlg.Control('Quality').value() == 4 ) {
			qLevel = 8;
			kbps = '256kbps';
		}
		else {
			qLevel = 10;
			kbps = '384kbps';
		}

		cmdToRun = '"X:\\ProgramFiles\\_ffmpeg\\ffmpeg-4.3.2-2021-02-27-full_build\\bin\\ffmpeg.exe" -i {filepath$} -c:a libvorbis -qscale:a ' + qLevel + ' {filepath|noext}_vorbis_q' + qLevel + '_' + kbps + '.ogg ';


		if (Dlg.result == 0) {
			DOpus.Output('User Cancelled');
		}
		else {
			cmd.RunCommand(cmdToRun);
		}
		
	}
	else {
		DOpus.Output('No files are selected');
	}	
}

Resources:

<resources>
	<resource name="Main" type="dialog">
		<dialog fontsize="8" height="78" lang="english" resize="yes" standard_buttons="ok,cancel" title="Convert to Vorbis OGG" width="201">
			<control height="8" name="Quality" resize="w" type="combo" width="102" x="66" y="24" default="2">
				<contents>
					<item text="q0 (~64kbps) Very Low" />
					<item text="q2 (~96kbps) Low" />
					<item text="q4 (~128kbps) Medium" />
					<item text="q6 (~192kbps) High" />
					<item text="q8 (~256kbps) Very High" />
					<item text="q10 (~384kbps) Ultra High" />
				</contents>
			</control>
			<control halign="right" height="10" name="static1" title="Quality:" type="static" width="54" x="6" y="26" />
		</dialog>
	</resource>
</resources>
3 Likes