picture home | art | events | music | rack extensions | downloads | pixel blog

omino pixel blog

pixels, motion, and scripting
david van brink // Sun 2008.09.21 19:35 // {after effects extendscript photoshop}

Omino Dialog Maker for ExtendScript

ExtendScript

My favorite Adobe applications are all scriptable. They use a scripting language called ExtendScript. I think it’s pure and compliant JavaScript (aka EcmaScript)… if it has any deviations, it’s in some subtle fashion that hasn’t affected me.

One thing you frequently need in a script is a means to gather input choices, so the script can be flexible. I rolled something up that handles this for many simple situations. I call it the Omino Dialog Maker. It’s a software library that lets you bring up an input dialog with just a couple of lines of code. It is mostly about 2 years old now, works pretty well.

Omino Dialog Maker

Here’s a simple example of a dialog made with the Omino Dialog Maker.

And here’s the code to produce it:

#include "ominoDialogMaker.jsx"

var omd = newOminoDialog("Example Omino Dialog");

omd.number("a number","n",88.21);
omd.string("a string","s","your name here");
var result = omd.run();

if(result == null)
	alert("Cancelled\nYou clicked \"cancel\".");
else
	alert("n is " + result.n + ", and s is \"" + result.s + "\"");

That’s pretty handy, isn’t it? As you can see, omd.run() populates a result variable with the contents of the dialog.

I admit it: tt’s not the best possible dialog and layout. It’s a little clunky looking. But it gets the job done, lets me type in a few numbers and set meat of the script to work.

More UI Elements

Here’s a dialog which shows the various UI elements supported by Omino Dialogs:

And, here’s the code which produced it:

#include "ominoDialogMaker.jsx"
function go()
{
	// setting up a dialog is easy. you can add entries for basic types of
	// string and number, and checkbox and radio buttons, and the
	// dialog is presented reasonably, with very little work.

	var omd = newOminoDialog("Example Omino Dialog");

	omd.boxedText(5,"This is an example of an Omino Dialog. It runs \n"
		+ "with After Effects, Illustrator, and Photoshop, or just in the\n"
		+ "ExtendScript toolkit itself. It can handle simple parameter types."
		+ " (Running in " + app.name + " v" + app.version + ")"
	);
	omd.number("a number","n",15.7);
	omd.string("a string","s","a text value");
	omd.separator();
	omd.sectionLabel("basics");
	omd.checkbox("a checkbox","x",true,"subtitle");
	omd.menu("a menu","menu","cherries",["apples","bananas","cherries","dates","figs"]);
	omd.radioButtons("Choose One","r","red",["red","maroon","scarlet","crimson"]);
	omd.separator();
	omd.sectionLabel("files");
	omd.openFile("a file","jpgFileName","foo.jpg","Choose a JPEG File",".jpg");
	omd.selectFolder("a folder","folderName","/tmp","Choose a folder");
	omd.saveFile("save as","gifFileName","foo.gif","Save as GIF",".gif");s

	// when we "run" the dialog, we get back a result variable.
	// if you hit CANCEL, then the result is null.
	// if you hit OK, then the values are populated into the result.

	// note: you can kill photoshop by running the dialog from ExtendScript toolkit, then halting
	// the script with the dialog still up.

	var result = omd.run();

	if(result == null)
		alert("Cancelled\nYou clicked \"cancel\".");
	else
	{
		var s = "result from dialog:\n";
		for(var f in result)
			s += "   " + f + " := " + result[f] + "\n";
		alert(s);
	}
}
go();

If you’ve read this far, you’re hopefully asking, “Gee, where can I get the actual library?” Here’s the code, shown directly out of my source code repository. Download with the download button.


 

Trivia: UI Differences Across Adobe Applications

Omino Dialog Maker can be used for scripts in After Effects, Photoshop, and Illustrator, at least, and possibly other Adobe applications. I have noticed that the dialogs look slightly different in each of these apps! Not critically… For reference, here are screen shots from several.

12 comments
Austin Wallender // Mon 2008.09.22 09:549:54 am

This looks amazing. Can’t wait to try it out! Thanks for the hard work….

Justin Putney // Sun 2008.11.23 16:214:21 pm

Thanks a ton for posting, David! This is extremely useful. I used the Omino Dialog Maker code in my Merge Text for Illustrator extension:
http://ajarproductions.com/blog/2008/11/23/merge-text-extension-for-illustrator/

david van brink // Sun 2008.11.23 22:4710:47 pm

Yay! Glad you found it useful.

James Talmage // Sat 2008.11.29 08:298:29 am

David,
Thank you for sharing this much-needed script. I’ve just successfully modified one of my scripts which formerly relied upon three separate prompt() statements to obtain the user inputs needed for the script.

I have noticed one caveat, though, which I hope you can explain. In both my script modified to use Omino Dialog, and in your first sample script (the one which invokes a dialog with two inputs), if the user clicks Cancel, the alert appears as expected, but then Illustrator’s window minimizes, effectively “taking” the user to whatever OS or app window was previously active.

Any ideas on that?

Again, thanks much for Omino Dialog.

Illustrator CS3
Windows Vista Basic

david van brink // Sat 2008.11.29 16:294:29 pm

Hi James — thanks for your note. I’ve only used it extensively on Mac OS X; I use After Effects on Windows a little but haven’t seen that symptom. Will investigate further…

Thanks for the bug report! Any further info very welcome.

Joel // Tue 2008.12.30 16:104:10 pm

Thanks so much for the scripts! HOWEVER, I’m wondering if you or anyone can advise as to what is causing my “Window does not have a constructor” error that prevents this from working? Illustrator refuses to instantiate a window for me (jerk!).
I’m using AI CS2 on a Mac running Tiger and I am clueless as to the source of my misery. Thanks!!!

david van brink // Tue 2008.12.30 21:569:56 pm

Joel… I’ve only used CS3 and CS4. It’s… probably a clue. 🙁

Dave Stewart // Fri 2009.04.10 07:297:29 am

Just checking your work out now. Great stuff!

I’m wondering why you don’t use proper JavaScript for creating your objects though? Why not just make newOminoDialog a OminoDialog object, and instantiate with the “new” keyword?

Do you need some help writing JavaScript prototypes?

Let me know if you do – it will tidy up the global space a LOT.

Cheers,
Dave

david van brink // Sat 2009.04.11 17:005:00 pm

^^^ Dave, thanks!

If I understand rightly, the “real object-ness” is orthogonal to the global namespace pollution. That is, I could (and should) allow “new OminoDialog()” to work, and depending where the functions live will be in or out of the global name space.

But the real answer to your question is: When I first wrote this, I didn’t know about either of those issues. Version 2!

Dave Stewart // Sun 2009.04.12 07:367:36 am

Hey David,

Ah, yes, I understand! JavaScript is a bit of a dark horse – there’s a lot of power hidden away in there!

Well, as it happens I got all curious ysterday and decided to whip something OOP up yesterday, and I’m nearly done. I may put it on hold for a week or two as I have other projects pressing, but I’ll happily send it your way so you can see what it’s all about when I’ve finished.

Some nice ideas in your work, especially saving the values in once central place.

Cheers for now,
Dave

heavyboots // Mon 2009.05.4 16:014:01 pm

Wow, this is just the ticket. Barely stumbling around in JS (I usually use Applescript) so this looks like it will ease the pain a lot. Thanks!

PS: FWIW, I immediately hacked the buttons over to the right side as they just looked too weird on the left.

okRect.left = D_DIALOG_WIDTH – D_MARGIN – D_BUTTONWIDTH;
okRect.top = y;
okRect.right = okRect.left + D_BUTTONWIDTH;
okRect.bottom = okRect.top + D_CONTROLHEIGHT;

cancelRect.left = okRect.left – D_MARGIN – D_MARGIN – D_BUTTONWIDTH;
cancelRect.top = y;
cancelRect.right = cancelRect.left + D_BUTTONWIDTH;
cancelRect.bottom = cancelRect.top + D_CONTROLHEIGHT;

david van brink // Mon 2009.05.4 18:416:41 pm

!! you’re so right about the button placement! Always interested to see what you’re making with it.

oh, i dont know. what do you think?


/\/\/\/\/\/\/\/\

0.0224s
(c) 2003-2023 omino.com / contact poly@omino.com