
Security News
Feross on the 10 Minutes or Less Podcast: Nobody Reads the Code
Socket CEO Feross Aboukhadijeh joins 10 Minutes or Less, a podcast by Ali Rohde, to discuss the recent surge in open source supply chain attacks.
extendscript_dialogs
Advanced tools
A helper Class for quick ScriptUI dialogs in Adobe ExtendScript with UMD wrapper for cross-compatability with AMD and node.js require.
A helper Class for quick ScriptUI dialogs in Adobe ExtendScript with UMD wrapper for cross-compatability with AMD and node.js require.
The idea being to replace native dialogs with prettier ScriptUI versions that have optional additional functionality and customization. Plus a dropdown menu dialog... cause I use that a lot too.
Basically I got tired of rewriting an alert that has a "Do not ask again" checkbox.
All dialogs function like the native version or accept an options object with custom arguments with default settings as fallbacks.
Quick example of a confirmation dialog that has three buttons and a skip-me checkbox...
var weapon = confirm({text:"Kill it with...", skippable:true, buttons:["Boredom","Fire","Hugs"]});
// returns the index number of the button selected.
$.global space or your own namespace in a Dialogs objectIf running Node NPM, you can npm install ExtendScript_Dialogs to add to your node_modules folder
Clone or download the repo and copy the extendscript_dialogs.jsxinc to your project
var Dialogs = require("ExtendScript_Dialogs");
I don't know but it's probably not difficult? Firmly in the untested-but-should-work category
$.evalFile("<path>/extendscript_dialogs.jsxinc")
//@include "<path>/extendscript_dialogs.jsxinc"
Add to a build script or, I dunno, just copy-pasta it in there?
Make a "new" ExtendScript_Dialogs. Note: check the constructor options below for how to override native dialogs.
You can either pass a root object to attach the Dialogs object to, or directly capture the Dialogs object in a variable. Or both?
var myDialogDad = {};
var myDialogs = new ExtendScript_Dialogs(myDialogDad);// two ways to attach Dialogs object...through root arg or return capture
myDialogs.alert('Whatever dad. I don't need you.');
myDialogDad.Dialogs.alert('Can I borrow the car?');// hint, it's the same Dialogs object...
"new" constructor takes 2 optional arguments.
First argument is an alternate root object to tack on a 'Dialogs' alias.
By passing $.global as first arg, we get global Dialogs object!
var root = $.global;// root to add convenience aliases to
var overrideNative = false;// replace native dialogs or not
myDialogs = new ExtendScript_Dialogs(root, overrideNative);
Dialogs.alert('Like magic.');
Dialogs.dropdown(["Thing 1","Thing 2"]);
The second argument is whether or not to replace native JS dialogs with prettier ExtendScript versions.
// don't care about the Dialogs object right now... just native stuff
new ExtendScript_Dialogs(null, true);
alert('I've been overridden!');
var myBool = confirm('Do the thing?');
var myText = prompt('What to say?','Replace these words...');
The alert dialog has a variable-typed parameter to either mimic native Alert or add customization. Options:
/**
* Replaces standard alert with prettier and skippable ScriptUI version
* @param {String, Object} String of text or options object.
* args = {
* title:"Confirm",
* text:"Message",
* id:234,
* skippable:true,
* }
*/
new ExtendScript_Dialogs($.global, true);
alert("Beware!");
alert({text:"Beware!"});
The confirm dialog has a variable-typed first parameter to either mimic native Confirm or add customization.
Note: If you pass an options object as first argument, it returns the button number (0, 1, 2, etc) instead of a boolean value.
Options Object:
/**
* Replaces standard confirm with prettier and skippable ScriptUI version
* @param {String, Object} String of text or options object.
* Button order assumes first is cancel, last is accept.
* args = {
* title:"Confirm",
* text:"Message",
* id:234,
* skippable:true,
* buttons:["Cancel","Select","Delete"]
* }
*
* @return {Boolean, Number} boolean if 1st arg is string, index of the clicked button if 1st arg is options object
*/
new ExtendScript_Dialogs($.global, true);
var killCheck = confirm("Should I do it?");// returns true/false
// for more complex choices...
var weapon = confirm({text:"Kill it with...", skippable:true, buttons:["Boredom","Fire","Hugs"]});
// returns the index number of the button selected.
The prompt dialog has a variable-typed first parameter to either mimic native Prompt or add customization.
Options Object:
/**
* Replaces standard prompt with prettier and skippable ScriptUI version
* @param {String, Object} args String of text or options object.
* args = {
* title:"Prompt",
* text:"Message",
* defaultText:"Example...",
* multiline: true,
* id:234,
* skippable:true,
* buttons:["Cancel","Select","Delete"]
* }
* @param {String} defaultText String to put as default in text field.
*
* @return {String} Input from text field
*/
new ExtendScript_Dialogs($.global, true);
var answer = prompt("Favorite ice-cream flavor?","Margarine");
// for more complex choices...
var bio = prompt({text:"Write your life story here...", defaultText:"It was the best of times, it was the blurst of times.", multiline:true});
The dropdown dialog has a variable-typed first parameter as an array for quick use or as an options object to add customization.
Options Object:
/**
* Dialog with dropdown menu
* @param {Array, Object} args Array of strings or options object.
* options: {
* title:"Confirm",
* text:"Message",
* id:234,
* skippable:true,
* menuItems:["Salmon","Tuna","Eel"],
* buttons:["Cancel","OK"]
* }
*
* @return {String} Selected menu item
*/
new ExtendScript_Dialogs($.global, true);
var fish = Dialogs.dropdown(["Salmon","Tuna","Eel"]);
// for more complex choices...
var hero = Dialogs.dropdown({text:"Favorite Robotroid Character...", menuItems:["Black", "Red", "Blue", "Green", "Yellow"]});
What if you are looping through a bunch of things and want to have a dialog pop up once with the option to not ask again? Or maybe just be able to retrieve a previous dialog selection?
Gotcha covered. Behold the somewhat clunky dialog cache!
Dialogs.getCached(id) retrieves the saved properties from an id.
If no argument is passed, it defaults to an id of -1.
Cached data
Dialogs.clearCached(id) sets the saved properties from an id to undefined.
If no argument is passed, it defaults to an id of -1.new ExtendScript_Dialogs($.global, true);
for (i=0;i<5;i++)
{
var cached = Dialogs.getCached();
if(cached && cached.skippable) {
break;
} else {
alert({text:"You have been warned...", skippable:true});
}
}
Dialogs.clearCached();
for (i=0;i<5;i++)
{
var answer;
var buttons = ["Naw","Meh","Yeah"];
var cached = Dialogs.getCached(55);
if(cached && cached.skippable) {
answer = Dialogs.getCached(55).value;
button = Dialogs.getCached(55).button;
} else {
answer = prompt({text:"Tedious input", id:55, skippable:true, buttons:buttons});
button = Dialogs.getCached(55).button;
}
// could also get buttons and values down here with cache
$.writeln(buttons[button]);
$.writeln(answer);
}
Dialogs.clearCached(55);
This was hacked together and refactored a lot before it became an actual distributable thing so... it's not the prettiest. Emphasis was on making something really easy to use out of the box with extra bonus features. Not efficiency or elegance.
Also, I'm not trying to solve every dialog problem in one API. If there's something more complex than single input, several buttons, it's probably best to just make a custom dialog.
FAQs
A helper Class for quick ScriptUI dialogs in Adobe ExtendScript with UMD wrapper for cross-compatability with AMD and node.js require.
We found that extendscript_dialogs demonstrated a not healthy version release cadence and project activity because the last version was released a year ago. It has 1 open source maintainer collaborating on the project.
Did you know?

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Security News
Socket CEO Feross Aboukhadijeh joins 10 Minutes or Less, a podcast by Ali Rohde, to discuss the recent surge in open source supply chain attacks.

Research
/Security News
Campaign of 108 extensions harvests identities, steals sessions, and adds backdoors to browsers, all tied to the same C2 infrastructure.

Security News
OpenAI rotated macOS signing certificates after a malicious Axios package reached its CI pipeline in a broader software supply chain attack.