Help finishing script "random audio"

I use SelectEx to randomly select audiofiles to put on CD, stick, etc. as regular button. Now I would like to create a GUI-version. As I am not good in scripting, can someone please finish it?

In its window you can enter max. size to be selected (for example 700 MB for CD), the radio-buttons are for choosing filetype (mp3/all files).

Code:

<?xml version="1.0"?>
<button backcol="none" display="icon" textcol="none">
	<label>SC_SelectEx_Random_Size_GUI-beta</label>
	<tip>Gewählte Dateigesamtgröße zufällig markieren</tip>
	<user_label>Größe zufällig markieren</user_label>
	<icon1>#rename4</icon1>
	<function type="script">
		<instruction>@script JScript</instruction>
		<instruction>function OnClick(clickData) {</instruction>
		<instruction>    var cmd = clickData.func.command;</instruction>
		<instruction>    var dlg = clickData.func.Dlg();</instruction>
		<instruction>    dlg.window = clickData.func.sourcetab;</instruction>
		<instruction>    dlg.template = &apos;mydlg&apos;;</instruction>
		<instruction />
		<instruction>	var input1 = dlg(&quot;input1&quot;);</instruction>
		<instruction>	var radio1 = dlg(&quot;radio1&quot;);</instruction>
		<instruction>	var radio2 = dlg(&quot;radio2&quot;);</instruction>
		<instruction>	</instruction>
		<instruction>    var retVal = dlg.Show();</instruction>
		<instruction>    if (retVal == radio1) var filetype = &apos; &apos;;</instruction>
		<instruction>    if (retVal == radio2) var filetype = &apos;\.mp3$&apos;;</instruction>
		<instruction />
		<instruction>	var cmdLine = (&apos;&quot;SelectEx RANDOM FILES&apos; +filetype+ &apos;MAXSIZETOTAL=&apos;+input1+&apos;MB ITEMCOUNT=999999 DESELECTNOMATCH MAKEVISIBLE&quot;&apos;);</instruction>
		<instruction>	DOpus.Output(cmdLine);</instruction>
		<instruction>    cmd.RunCommand(&apos;dopusrt /argsmsgbox &apos; + cmdLine);</instruction>
		<instruction>}</instruction>
		<instruction />
		<instruction />
		<instruction>// cmd.RunCommand(&apos;&quot;SelectEx RANDOM FILES&apos; +typVal+ &apos;MAXSIZETOTAL=&apos;+sizeVal+&apos;MB ITEMCOUNT=999999 DESELECTNOMATCH MAKEVISIBLE&quot;&apos;);</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;118&quot; lang=&quot;german&quot; title=&quot;Größe zufällig markieren&quot; width=&quot;173&quot;&gt;</instruction>
		<instruction>			&lt;control halign=&quot;left&quot; height=&quot;8&quot; title=&quot;Wie viele MB sollen zufällig markiert werden?&quot; type=&quot;static&quot; valign=&quot;top&quot; width=&quot;149&quot; x=&quot;12&quot; y=&quot;8&quot; /&gt;</instruction>
		<instruction>			&lt;control halign=&quot;left&quot; height=&quot;12&quot; name=&quot;input1&quot; title=&quot;700&quot; type=&quot;edit&quot; width=&quot;36&quot; x=&quot;12&quot; y=&quot;24&quot; /&gt;</instruction>
		<instruction>			&lt;control checked=&quot;yes&quot; height=&quot;10&quot; name=&quot;radio2&quot; title=&quot;MP3-Dateien&quot; type=&quot;radio&quot; width=&quot;64&quot; x=&quot;12&quot; y=&quot;73&quot; /&gt;</instruction>
		<instruction>			&lt;control height=&quot;10&quot; name=&quot;radio1&quot; title=&quot;Alle Dateien&quot; type=&quot;radio&quot; width=&quot;51&quot; x=&quot;12&quot; y=&quot;58&quot; /&gt;</instruction>
		<instruction>			&lt;control halign=&quot;left&quot; height=&quot;8&quot; title=&quot;MB gesamt&quot; type=&quot;static&quot; valign=&quot;top&quot; width=&quot;37&quot; x=&quot;51&quot; y=&quot;26&quot; /&gt;</instruction>
		<instruction>			&lt;control halign=&quot;left&quot; height=&quot;8&quot; title=&quot;Dateityp:&quot; type=&quot;static&quot; valign=&quot;top&quot; width=&quot;30&quot; x=&quot;12&quot; y=&quot;44&quot; /&gt;</instruction>
		<instruction>			&lt;control close=&quot;0&quot; height=&quot;14&quot; name=&quot;button1&quot; title=&quot;Ok&quot; type=&quot;button&quot; width=&quot;72&quot; x=&quot;45&quot; y=&quot;95&quot; /&gt;</instruction>
		<instruction>		&lt;/dialog&gt;</instruction>
		<instruction>	&lt;/resource&gt;</instruction>
		<instruction>&lt;/resources&gt;</instruction>
	</function>
</button>


The SelectEx part might need some fine tuning.

function OnClick(clickData) {
    var cmd = clickData.func.command;
    var dlg = clickData.func.Dlg();
    dlg.template = 'mydlg';
    dlg.Show();

    var input1 = dlg.Control('input1').value;
    var radio1 = dlg.Control('radio1').value;
    // var radio2 = dlg.Control('radio2').value;

    var filetype = radio1 ? '' : ' .mp3$';

    var cmdLine = 'SelectEx RANDOM FILES' + filetype + ' MAXSIZETOTAL=' + input1 + 'MB ITEMCOUNT=999999 DESELECTNOMATCH MAKEVISIBLE';
    DOpus.Output(cmdLine);
    // cmd.RunCommand('dopusrt /argsmsgbox ' + cmdLine);
}
1 Like

Thanks, I now have the correct output. But how to excute the SelectEx-script at the end (I think we don't need "var cmdLine", just the command itself)? DO does not find it:

cmd.RunCommand('"SelectEx RANDOM FILES' + filetype + 'MAXSIZETOTAL='+input1+'MB ITEMCOUNT=999999 DESELECTNOMATCH MAKEVISIBLE"');

Well, the double quotes were removed for a reason :slight_smile:

Which quotes you mean?

Edit: Solved, I had to remove them!