# Simplify JScript

**URL:** https://resource.dopus.com/t/simplify-jscript/45909
**Category:** Help & Support
**Tags:** feature-request
**Created:** [September 19, 2023, 3:43pm UTC](https://resource.dopus.com/t/simplify-jscript/45909 "2023-09-19T15:43:32Z")
**Posts on this page:** 3
**Page:** 1

<div class="post-metadata">

### Author: ![WKen](https://resource.dopus.com/letter_avatar_proxy/v4/letter/w/eb9ed0/32.png) [@WKen](https://resource.dopus.com/u/WKen)
#### Post date: [September 19, 2023, 3:43pm UTC](https://resource.dopus.com/t/simplify-jscript/45909/1 "2023-09-19T15:43:32Z")

</div>

I was new to DOpus last year and proposed adding new simplified script.  
[Hello! Request to add a new simplified script - Help & Support - Directory Opus Resource Centre (dopus.com)](https://resource.dopus.com/t/hello-request-to-add-a-new-simplified-script/41051).

Now that I have learned some basic JScript, I know that adding another scripting language may be redundant, but I think JScript can be simplified to make scripting more efficient, more friendly to new users, and easier to get started.  
Now my idea is to add some built-in functions, like some common dialogs.  
`inputBox(title, topic, notes, default value, style of dialog, width, height, drop-down items, iconFile)`

```javascript

	var tab = DOpus.listers(0).activetab;
	var defValue = tab.selected(0).name_stem;
	
	// inputBox(title, topic, notes, default value, style of dialog, width, height, drop-down items, iconFile)
    result = inputBox("Directory Opus", "Move Here to New Subfolder", "Select or enter folder name or subpath", defValue, "combo", 500, 208, "selectedNames", "D:\\Icons\\MOVE.png");
	msgbox(result)

function inputBox(title, topic, notes, defValue	, style, width, height, drop_downItems, iconFile)
{
    var dlgInpput = DOpus.Dlg();
    dlgInpput.title = topic;
	if (style == "combo")
        dlgInpput.template = "dlgCombox";
	dlgInpput.detach = true;
    dlgInpput.Create();
	dlgInpput.Control("static").style = "b";
	dlgInpput.Control("static").label = topic;
	dlgInpput.Control("static2").label = notes;
	dlgInpput.Control("static3").label = iconFile;
	dlgInpput.Control("combo").label = defValue;
	dlgInpput.Control("combo").SelectRange(0, -1);
	
	dlgInpput.Control("static").cx = width-12;
	dlgInpput.Control("static2").cx = width-12;
	dlgInpput.Control("static2").cy = height/4;
	if (width > 501)
	    dlgInpput.Control("combo").cx = width-42;
	else if (width < 801 && width > 501)
	    dlgInpput.Control("combo").cx = width-402;

	dlgInpput.Control("combo").y = height-(height/1.9);
	dlgInpput.cx = width;
	dlgInpput.cy = height;
	
	if (drop_downItems == "selectedNames") {
        for(var e = new Enumerator(tab.selected); !e.atEnd(); e.moveNext()) {
	        dlgInpput.Control("combo").AddItem(e.item().name_stem_m);
		}
    }
    
    dlgInpput.Show();

//-- Add string trim() method
String.prototype.trim = function(s){s=s||"\\s";return this.replace(new RegExp("^("+s+"){1,}\|("+s+"){1,}$","g"),"");}

// msg loop	
	do
	{
		msg = dlgInpput.GetMsg();
/*
        // Selection
		if(msg == true && dlgInpput.Control("combo").focus == true) {
		   DOpus.Output(dlgInpput.Control("combo").label);
		}
*/
        // Result, perform the move operation
		if (dlgInpput.result == 1) {
            return dlgInpput.Control("combo").label.trim();
		}
/*		
		// If the button 3 is pressed
		if(dlgInpput.result == 2) {
		DOpus.Output("Button 3 is pressed");
		}
		
		// If the button 4 is pressed
		if(dlgInpput.result == 3) {
		DOpus.Output("Button 4 is pressed");
		}
*/
	} while (msg == true);
}

function msgbox(message)
{
    var dlgMsg = DOpus.Dlg();
	dlgMsg.message = message;
	dlgMsg.buttons = "&OK";
	dlgMsg.show
	return dlgMsg.Result
}

==SCRIPT RESOURCES
<resources>
	<resource name="dlgCombox" type="dialog">
		<dialog fontsize="8" height="78" lang="english" resize="yes" title="Directory Opus" width="322">
			<control edit="yes" height="40" name="combo" type="combo" width="306" x="8" y="40" />
			<control close="3" enable="no" height="14" name="btn4" resize="xy" title="&amp;4" type="button" visible="no" width="50" x="101" y="57" />
			<control close="2" enable="no" height="14" name="btn3" resize="xy" title="&amp;3" type="button" visible="no" width="50" x="155" y="57" />
			<control halign="left" height="8" name="static" title="Topic" type="static" valign="top" width="280" x="30" y="10" />
			<control halign="left" height="16" name="static2" title="Notes" type="static" valign="top" width="280" x="30" y="22" />
			<control halign="center" height="14" image="yes" name="static3" title="Icon" type="static" valign="top" width="14" x="8" y="7" />
			<control close="1" default="yes" height="14" name="btnOK" resize="xy" title="&amp;OK" type="button" width="50" x="209" y="57" />
			<control close="0" height="14" name="btnCancel" resize="xy" title="&amp;Cancel" type="button" width="50" x="263" y="57" />
		</dialog>
	</resource>
</resources>

```

Maybe more detailed or simplified.  
`inputBox(topic, notes, default value, width, height, drop-down items, iconFile)`  
I often use AutoHotkey's MsgBox, ToolTip, and TrayTip functions.  
There are also search, format values, format text and others.

---

<div class="post-metadata">

### Author: ![bytespiller](https://resource.dopus.com/user_avatar/resource.dopus.com/bytespiller/32/23964_2.png) [@bytespiller](https://resource.dopus.com/u/bytespiller)
#### Post date: [October 3, 2023, 6:12am UTC](https://resource.dopus.com/t/simplify-jscript/45909/2 "2023-10-03T06:12:38Z")

</div>

Opus 13 has a new Evaluator scripting now (in addition to all previous things): [Evaluator [Directory Opus Manual]](https://docs.dopus.com/doku.php?id=evaluator)

See also this page: [Evaluator Functions [Directory Opus Manual]](https://docs.dopus.com/doku.php?id=reference:evaluator)

---

<div class="post-metadata">

### Author: ![WKen](https://resource.dopus.com/letter_avatar_proxy/v4/letter/w/eb9ed0/32.png) [@WKen](https://resource.dopus.com/u/WKen)
#### Post date: [October 3, 2023, 11:22am UTC](https://resource.dopus.com/t/simplify-jscript/45909/3 "2023-10-03T11:22:20Z")

</div>

Marvelous!
