Category Archives: Adobe ExtendScript

Adobe ExtendScript related posts!

Hard at work on an InDesign plugin! (wait for beta testing release!)

In-Design plugin preview (one of the few dialogs of the UI)
In-Design plugin preview (one of the few dialogs of the UI)

Once I said:

Developing software is like panning for gold, you may find something that shines to you, but before getting it to market you just don’t know if it is real!!

I’m hard at work on my first InDesign plugin! and that’s why I’m not that active for the moment here! It’s been more than two weeks already that I started working on it and it’s going very well so far!

So I think I’ll be able to announce a pre-release beta testing call for it in few days (or weeks perhaps!), I worked really hard on it and the plugin with all its options won’t be available for free ( will be free during beta testing) but I will release a free version as well for folks just like myself who can’t afford paying for these kind of stuff! After all I hope to be able to sell a few of it after all these nights staying awake and writing codes till morning!

Please let me know if you are interested in the beta release.
Also I have to pick a name for my plugin! so please let me know if you have an idea about it! :))

Ok, back to work! 😉 have a good day!

manage paths in Adobe Extend-Script

Adobe Exten-Script (source: internet)
Adobe Exten-Script (source: internet)

Managing paths obtained from Adobe Extend-Script, Specially when you want to share these paths with an external 3th application (to do things which aren’t possible with just ExtendScript) is kind of difficult!
For instance let’s say we want to get the Path of an In-Design file being opened (and in front) in in-Design, we may simply do:


And get:

alert(app.activeDocument.filePath);
alert(app.activeDocument.filePath);

But there is obviously 3 (+1 not obvious here!) possible problems with this path (even if you can transfer that variable as easily as shout it out in an alert! look at #3):

  1. the Tilde (~) character at the beginning, an environment variable meaning “Home Directory“, which is not a recognizable standard character in all the different programing environments (for instance it’d be %~dp0 in Batch scripting and user.home, (more or less!) in Java) although it is supposed to be the absolute path using above code!
  2. existence of Slash characters (/) in the path instead of Backslash (\), making it hard (not so much tho!) to send it through a JSON package for example (or save it in a batch file -again- for instance), be-cause in most environments it’d be considered as a escape character and not a path level separator.
  3. It is an object and not a string (apparently!) and you can send, save or sometimes even use the myPath variable for instance directly! (it will give you an [object] instead of the path, which I guess should be the parent File object itself)
  4. in addition if our file wasn’t in our Desktop folder and was in a disk drive instead, we would have this problem too:
    alert(app.activeDocument.filePath);
    alert(app.activeDocument.filePath);

    as you can see, an additional Slash character (/) before the Drive letter (c)! which is incomprehensible to me why it is!! but it seems that Extend-Script itself doesn’t have any problem with it, but as I said when you want o communicate with 3th party apps it will become a problem immediately!

  5.     So as you may guess there is a lot of solutions for any and each of mentioned problems, but here I just wanted to suggest the most convenient one I figured out after trying a lot of different shenanigan techniques!
    Here we used Regular Expression Patterns to Replace() all (by using the g pseudo) the Slashes with Backslashes and by using fsName instead of filePath eliminating other problems (like getting “relative paths” (or fake absolutes!) instead of absolutes and the beginning slash character)
    And the result:

    alert(app.activeDocument.fullName.parent.fsName).toString().replace(/\\/g, '/');
    alert(app.activeDocument.fullName.parent.fsName).toString().replace(/\\/g, ‘/’);

    Awesome! 😀
    Please let me know if you have a better idea to this or if you see a problem or something, I appreciate it 😉
    mim,

working with measurement units in adobe extendScript

measurement_units (img from internet)
measurement_units (img from internet)

While working with Adobe ExtendScript to extend Adobe CS features (through scripts and/or plugins), there is a good chance you need to get or set an elements dimensions (document dimensions for instance).
When you ask the Software about the dimensions, it will give you back a number, but this number could be in a lot of different units (Points, Picas, Inches, Inches Decimal, Millimeters, Centimeters, Ciceros, Agates, Pixels, etc.) and it’s gonna be the same when you set a number as well.
There is a lot of different ways to handle this issue, like getting the unit as well and trying to convert them etc. but it may add a huge overload on your code, your time and a lot of unnecessary complexity which can make your code harder to debug as-well.

Here I’ll put a simple solution I use in my own codes which may come helpful to you too (This code is written for In-design but should work less or more for the whole CS collection -maybe with a bit of tweaking- ):

I just get the current document units (for both Vertical and Horizontal measurement units in In-Design), keep them in a (pair of) variable(s) (I check to see if the variable is defined before and set it if it isn’t defined already, doing this we can be sure that even if we forgot to remove the vars later on, we don’t set them to our newly defined units again), change the units (for the whole document) and run my code and then when I was done with it change it back to original units and remove the created variables.
I found this technique to be the easiest, cleanest, fastest and the most performant way to handle the units issue in extend-script.

Here is the simple code I use; two functions, one to run before the main script and one when the script was done to set everything back to what they were before we run the script:

Note: here I use the very front document but you can easily pass desired document to the function through an argument as well.

Setinterval for Adobe ExtendScript

If you start working on an extension for one of Adobe CS products it can be really annoying or even disappointing once you find out that there is not any of java-script timing events available!
No setInterval, no timeout! no nothing! which means you don’t even have a choice, all the code you write, HAS TO be blocking!
That was (and probably is still kind of!) my situation! in fact, I’m working on my memoir, and both in my university and our lab place I have access to the whole set of Adobe products, (Oh, forgot to say: I’ll use Indesign to publish/design (page-making) my memoir), and since it have never been convenient for me to do things the easy way, I decided to write a plugin for In-Design so it will do for me what I wanted to do! Yeah, pretty much my first essay on creating an extension for an Adobe product…

Let’s make it short for you (I’ll probably talk more about that plugin, once it was ready!), I did a lot of research and read almost 500 pages of (really bad documented) adobe documents! to find out that there is no way to write a non-blocking check-loop; BUT…

But after I gave up, I thought it will bother me if I don’t try the last, and least probable idea! and that was the answer! (kind of) in fact I read almost all the possible event objects in Adobe ID and none of them were useful, but one of them raised my curiosity at-least and I thought give it a try! It is onIdle event and obviously it trigers on software IDLE time but it is more than that! in-fact you can check for system state in really short amounts of time (or long!) and it will return it to you, and that’s called an interval!! I would guess probably it won’t be precise but it would be enough good most certainly to help one to write a non-blocking UI or atleast give the option to user to choose the way s/he prefer (having the entire software freezes for the duration of the process or do it in the backrgund!)

Voila quoi!

Sample code:

Please let me know if you need more info / samples on it! my problem is solved now but I couldn’t find any helpful information online AT ALL, so I though I’d share it, 😉

 

there is an $.sleep() method available which that too, of course, is blocking!