Tools for EventScripter

System function: prompt()

Description

prompt(string title, string text) : string

Shows a dialog with input field. Returns string if confirmed, otherwise null.

Example

// Trigger Required: "Interval"
// Options recommended: 3000ms, synchronous

require(JD_HOME + "/eventscripter/system/prompt.js");

alert(prompt("title", "Hello world"));

Sourcecode

JD_HOME/eventscripter/system/prompt.js
/*jslint browser, long */
/*global getEnvironment, callSync, JD_HOME, alert */
function prompt(text, defaultText) {
    "use strict";

    text = text.replace("\r", "\\r");
    text = text.replace("\n", "\\n");
    var env = getEnvironment();
    var ret = null;
    switch (env.getOSFamily()) {
    case "WINDOWS":
        ret = callSync(JD_HOME + "/eventscripter/system/bin/prompt.bat", "JD2 - EventScripter", text, defaultText);
        ret = (
            (ret)
            ? ret.substring(1, ret.length - 2)
            : null
        ); // remove the leading "1". Its just a dummy to catch the null return
        break;
    default:
        alert("Sorry, your OS is yet not supported for ExDialog-prompt()");
    }
    return ret;
}
JD_HOME/eventscripter/system/bin/prompt.bat
@echo off
SETLOCAL EnableDelayedExpansion

SET _title=%~1
SET _text=%~2
SET _default=%~3

set _text=%_text:\r="&vbCr&"%
set _text=%_text:\n="&vbLf&"%

:uniqueTempVbs
set "vbsFileName=%TEMP%\~%RANDOM%.vbs"
if exist "%vbsFileName%" goto :uniqueTempVbs

ECHO Wscript.Echo Inputbox("!_text!","!_title!","!_default!")>%vbsFileName%
FOR /f "delims=/" %%G IN ('cscript //nologo %vbsFileName%') DO set _input=%%G
DEL %vbsFileName%

if "%_input%" NEQ "" (
    echo 1%_input%
)

ENDLOCAL