Using a regular expression to convert an image name to a path

Mike and I started an interesting discussion about using ExtendScript to import images from a base file name that the user enters. One of the key tasks is to figure out how to take a base file name that uses their syntax and derive a full path from it. Based on Mike’s examples, I came up with the following ExtendScript function:

This function illustrates the power of regular expressions. The basic regular expression is this:

Find 3 uppercase letters: [A-Z]{3}

followed by four digits: \d\d\d\d

The parentheses “capture” parts of the match and put them into special variables in the form of $#, where # is a number from 1 to 9. To figure out what number goes with what set of parentheses, you start counting from the left. So, in our regular expression

([A-Z]{3}) will be $1. In our example, this will be MSP.

((\d)\d) will be $2. In our example, this will be 43.

(\d) nested in $2 will be $3. In our example, this will be 4.

and (\d\d) will be $4. In our example, this will be 21.

We can use these variables to build up our path. Notice the $# variables in the replacement string (color-coded for clarity):

This will become

The backslash in JavaScript is an escape character, so to get the literal backslash character, we have to use 2 where we want 1.

Copy the function into the ExtendScript Toolkit and try a few filenames that use this format, and you will get the correct path every time. Regular expressions are a deep topic, but as you can see, they are very powerful for parsing tasks like this.


FrameMaker 10 ExtendScript: The Object Model

Thank you to all that attended this webinar. I will post the link to the recording as soon as it is available. In the meantime, here is a link to the FrameMaker Object Model chm file and webinar slides:

Here is a link to the FrameMaker 10 FDK:

After you install it, the documentation will be in the docs folder.

Arnis asked about dumping a list of properties for an object. In FrameScript it is easy:

With ExtendScript, you can use a function; in this case, I am writing to the JavaScript Console instead of the FrameMaker Console:

Please let me know if you have suggestions for future webinars. Thanks again for all your support.


ExtendScript Webinars: What Do You Want to Learn?

I just finished my second FrameMaker 10 ExtendScript webinar, which I enjoyed immensely. The first one was done in conjunction with Adobe, the second was sponsored by Carmen Publishing Inc. I would like to do more ExtendScript webinars and want to know what topics people are interested in. Please leave comments with suggestions for ExtendScript topics. Thank you very much.


In Memory of Bruce Foster

Bruce Foster, creator of many fine FrameMaker plugins, passed away suddenly on Saturday, June 11, 2011. Although Bruce had been diagnosed with multiple myeloma in September 2010, his death still came earlier than was expected. Bruce’s plugins for FrameMaker were BookInfo, ImpGraph, MifSave, MifToFM, RtfSave, and his most famous, Archive.

Bruce’s website is now offline and, as far as I know, his plugins are no longer available¬† for sale.

Adobe Engineering has just released a free ExtendScript script for archiving FrameMaker 10 books:

I haven’t tested the script yet, so I can’t necessarily recommend it, but it is certainly worth looking at.

– Rick

FrameMaker 10 and ExtendScript Automation Slides and Samples

Last week’s FrameMaker 10 and ExtendScript Automation eSeminar went well in spite of a few glitches. Thank you to Adobe and Tom Aldous for graciously hosting and promoting the seminar. Thank you especially to all that attended and submitted questions.

As promised, we are making the slides and sample scripts available for download. You can download the slides from:

The samples are at:

The sample scripts may not meet your current requirements, but there are portions of each script that you can reuse in your own scripts. You can also use them to learn good scripting practices and how to approach similar problems. In future posts, we will dissect one of the scripts so you can learn solid techniques for writing your own.

Here is a link to the eSeminar recording: