TweetFollow Us on Twitter

Adobe CS3 and AppleScript

Volume Number: 24 (2008)
Issue Number: 02
Column Tag: Application Scripting

Adobe CS3 and AppleScript

by Ben Waldie

Upgrading an application, despite giving you access to the latest and greatest features, tends to present some nagging questions. Will your existing documents still work with the new version of the application? Will any of your existing data, settings, or preferences be lost or overwritten? Will conflicts with other applications or software arise?

If you've incorporated the application into an AppleScript-based automated workflow, as is the case with many Adobe users, then some additional concerns may arise. Will your existing AppleScripts continue to work? If not, how long will it take to update them? The answers to these questions depend entirely on the changes made by the application developer. If the developer has changed the application significantly, then the AppleScript implementation may also have changed significantly too. If this is the case, then many changes to your existing scripts could be necessary.

Fortunately, Adobe applications seem to have good backward compatibility. In my experience, when installing updated Adobe software, I've generally found that only minor changes, if any, are required in my existing scripts. New terminology may exist for new application features, but existing terminology rarely seems to change much. And, if it does, then it's usually well documented. In this month's column, we'll explore some of the scripting changes in Adobe Creative Suite 3, as well as provide some tips for upgrading your existing AppleScripts.

Whenever upgrading an application, whether it's part of an automated workflow or not, it's always a good idea to begin by backing up your existing data. Then, if you've got the means to do so, set up a test environment, where you may conduct parallel testing with the new software. Make sure it works as expected, and make any necessary changes to existing AppleScripts. When you're sure things are working as expected, then begin integrating the updated application and scripts into your live workflow.

Acrobat 8.x

Throughout the AppleScript community, it's widely assumed that Adobe has ceased expanding Acrobat Professional's AppleScript support, in favor of the cross platform JavaScript. Therefore, I'm afraid that any new scripting functionality in Acrobat Professional 8.x (which is included with CS3) is JavaScript-specific. According to Acrobat's JavaScript API reference guide, Acrobat Professional 8.x introduces a handful of new and modified object properties and methods. However, none of these are directly accessible via AppleScript.

That said, you can access all of Acrobat's JavaScript functionality from AppleScript by using the do script command, and passing it the JavaScript code you wish to execute or directing it to a file containing JavaScript code. Just be sure that you've enabled JavaScript in Acrobat's preferences.

The following simple example demonstrates how to use Acrobat's do script command to retrieve the title property of the frontmost opened document:

tell application "Adobe Acrobat Professional"
   do script "this.info.title;"
end tell
--> "My Document"

Acrobat Professional still includes limited AppleScript support for performing some basic functions, such as opening documents, deleting pages, inserting pages, and printing pages. If you've got an existing script that uses this terminology, then it will probably continue to work.

Acrobat's AppleScript terminology hasn't been updated in quite some time and it doesn't look likely to be expanded again in the future. Acrobat's JavaScript support is far more robust, and for best results and a greater chance of future compatibility, I recommend using it whenever automating Acrobat. You can find a comprehensive guide to Acrobat's JavaScript terminology on Adobe's developer website using the link provided later in this column. You can also test your JavaScript code within Acrobat itself by enabling the JavaScript debugger. To display the debugger, simply type Command+J. See figure 1.


Figure 1. Acrobat's JavaScript Debugger.

At the time this column was written, Adobe had not yet officially updated Acrobat Professional for Mac OS X 10.5 Leopard. According to Adobe's Leopard capability guide, the estimated release date for this update is sometime in January of 2008.

Acrobat Distiller

Like Acrobat Professional, Acrobat Distiller's AppleScript support remains unchanged in version 8.x. It contains a few basic terms, the most useful being the distill command, which may be used to convert a specified file to PDF format, using a specified PDF settings file.

Bridge CS3

Bridge CS3 introduces basic AppleScript support in the form of a do javascript command. Although this may seem insignificant, like Acrobat's do script command, this command gives AppleScripters access to Bridge's extensive JavaScript implementation. The following example code demonstrates how to use this command to run a slideshow of selected images, using Bridge's current slideshow options:

tell application "Bridge CS3"
   do javascript "var thumbs = app.document.getSelection();
   app.runSlideshow(thumbs);"
end tell

Illustrator CS3

Illustrator CS3 includes a number of AppleScript enhancements. Here are some that may be of particular interest. For a complete list of changes, check out the Illustrator CS3 Scripting Guide.

Commands have been added for undo and redo. To undo the last operation, you would use the following code:

tell application "Adobe Illustrator"
   undo
end tell

The path item class now possesses a read-only length property, allowing you to determine the length of the path, in points. Previously, you would have had to calculate this, based on the position of the path's ends.

tell application "Adobe Illustrator"
   tell current document
      length of path item 1
   end tell
end tell
--> 116.14274597168

Open file and export options have been expanded. AutoCAD and Freehand open file options are newly accessible via AppleScript, as are AutoCAD export options. In addition, Photoshop open options have been expanded to include a preserve layers property and a layer comp property. Flash export options have also been expanded to include additional properties, including export all symbols, export version, Flash playback security, include metadata, and more. Consult the Open Options Suite and Export Options Suite in Illustrator's AppleScript dictionary to access these classes and properties.

InDesign CS3

InDesign CS3 only appears to have a handful of scripting changes. This means that you should have few, if any, changes to make to existing CS2 AppleScripts, in order for them to work with CS3. Primarily of interest are the following:

The place command, which is used to place a file onto a page, spread, or page item, has been updated to return a list of items placed, rather than an individual item placed. The reason for this change is that in some instances, the place command may be used to place multiple objects. For example, the following code places a specified image on two different pages in the active document:

set theImage to choose file with prompt "Choose an image to place:"
tell application "Adobe InDesign CS3"
   tell active document
      place theImage on {page 1, page 2}
   end tell
end tell
--> {{image id 218 of rectangle id 222 of page id 177 
of spread id 172 of document "Untitled-1" of application "Adobe InDesign CS3"},
{image id 223 of rectangle id 225 of page id 201 of spread id 196 of
document "Untitled-1" of application "Adobe InDesign CS3"}}

The resize, rotate, and shear commands have been replaced by a more generic transform command, which can be used to perform multiple types of transformations. To use this command, your script must first create what's known as a transformation matrix, which will serve as the settings for the transformation. A transformation matrix object possesses various properties, such as horizontal and vertical scale, shear angle, rotation angle, and so forth, which may be specified when the transformation matrix is created. These properties will control how the specified objects will be transformed when the transform command is used. See figure 2.


Figure 2. The properties of a transformation matrix.

This is sure to confuse even the most experienced scripters. So, perhaps the best way to illustrate the creation of a transformation matrix and the use of the transform command is with an example. This example code scales the selected page items in the active document to 25%.

tell application "Adobe InDesign CS3"
   -- Create a transformation matrix that will scale to 25% horizontal and 25% vertical
   set theTranformationMatrix to make transformation matrix with ¬
   properties {horizontal scale factor:0.25, vertical scale factor:0.25}
   -- Get the selected page items
   set thePageItems to selection
   -- Transform the selected page items using the transformation matrix that we created earlier
   transform thePageItems in parent coordinates from top left anchor with ¬
   matrix theTranformationMatrix
end tell

Some additional related commands have also been added to InDesign CS3, including transform again, transform again individually, and clear transformations.

Script Versioning

InDesign possesses a unique feature, which I have yet to discover in any other scriptable applications. This feature, known as script versioning, allows InDesign CS3 to run scripts that were written for earlier versions of InDesign. This means that you theoretically should be able to run your existing InDesign CS or CS2 AppleScripts in InDesign CS3 without making any terminology changes. Actually, script versioning is not new to InDesign CS3, and was around in CS2 as well.

To utilize this feature, your script must be written to target InDesign CS3, but use terms from InDesign CS or CS2 (utilizing AppleScript's using terms from clause). You must also set InDesign's script preferences (via your script) to use the scripting implementation version appropriate for your script. For example:

-- Target InDesign CS3
tell application "Adobe InDesign CS3"
   -- Change the scripting implementation version to CS2
   set version of script preferences to 4.0
   -- Perform some CS2 code
   using terms from "InDesign CS2"
      -- Add your InDesign CS2 code here
   end using terms from
end tell

Please note that, in order for the code above to compile, you would need to have both InDesign CS3 and CS2 installed on your development machine. However, only CS3 would need to be installed on the machine that will run the script.

Photoshop CS3

Like the other CS3 applications, Photoshop doesn't introduce a large number of scripting changes. Here are a few:

There are now two separate versions of Photoshop, each with slightly different options. The version you have depends on the Creative Suite package you have purchased. Creative Suite Standard comes with Photoshop Standard, whereas Creative Suite Premium comes with Photoshop Extended. Your scripts can now determine the version of Photoshop installed by using the new feature enabled command. For example, this code checks to see if Photoshop is the extended version. A boolean value is returned.

tell application "Adobe Photoshop CS3"
   feature enabled name "photoshop/extended"
end tell
--> true

Photoshop Extended includes a new feature that allows you to manually count items in an image by placing markers throughout the image. These count markers are accessible via AppleScript using the count item class. The following example code retrieves a list of count items in the current document.

tell application "Adobe Photoshop CS3"
   every count item of current document
end tell
--> {count item 1 of document "My Photo" of application "Adobe Photoshop CS3", ¬
  count item 2 of document "My Photo" of application "Adobe Photoshop CS3"}

Photoshop now includes a refresh command, which may be used to allow the application to refresh prior to proceeding with further script execution. For example:

tell application "Adobe Photoshop CS3"
   refresh
end tell

Photoshop now includes a Photoshop open dialog command. When executed, this command displays Photoshop's open dialog, allowing the user to choose the desired files. See Figure 3. References to the chosen files are then returned to the script for further processing.

tell application "Adobe Photoshop CS3"
   Photoshop open dialog
end tell
--> {file "Macintosh HD:Users:bwaldie:Desktop:My Photo.png"}


Figure 3. Photoshop's Open Dialog.

Scripting Documentation

Adobe's scripting documentation is quite extensive, and it keeps getting better with each new release. When upgrading to CS3, one thing that you're likely to notice is that much of the scripting documentation has been re-organized and/or expanded. You can find the CS3 scripting documentation in the following locations:

Acrobat Scripting Documentation (JavaScript only)

Online at http://www.adobe.com/devnet/acrobat/javascript.html

Bridge Scripting Documentation (JavaScript only)

Online at http://www.adobe.com/devnet/bridge/

On the CS3 Content CD in /Documentation/Scripting/Adobe Bridge CS3/

Illustrator Scripting Documentation (AppleScript, JavaScript, and VBScript)

Online at http://www.adobe.com/devnet/illustrator/scripting/

On the CS3 Content CD in /Documentation/Scripting/Adobe Illustrator CS3/

Installed with Illustrator in /Applications/Adobe Illustrator CS3/Scripting/Documentation/

InDesign Scripting Documentation (AppleScript, JavaScript, and VBScript)

Online at http://www.adobe.com/products/indesign/scripting/

On the CS3 Content CD at /Documentation/Scripting/Adobe InDesign CS3/

Photoshop Scripting Documentation (AppleScript, JavaScript, and VBScript)

Online at http://www.adobe.com/devnet/photoshop/scripting/

On the CS3 Content CD in /Documentation/Scripting/Adobe Photoshop CS3/

Installed with Photoshop in /Applications/Adobe Photoshop CS3/Scripting Guide/

In CS3's scripting documentation, you'll find example code, terminology guides, tutorials, scripting version histories, and more.

In Closing

As we've discussed, the AppleScript enhancements in CS3 primarily offer AppleScript support for new features, or enhance existing support with new properties or parameters. Not too many actual changes to existing support have been made, with the exception of a few bug fixes here or there. Because of this, it's unlikely that you'll encounter major issues when upgrading to CS3. However, it's still recommended that you conduct parallel testing and make any necessary changes prior to implementing any new software in a live workflow.

As you continue scripting the applications of the Adobe Creative Suite, be sure to consult the scripting guides and documentation, as these are valuable resources that can often help to clarify things and put you back on track, should you run into trouble. Adobe also provides online user-to-user forums, which offer an excellent way to ask questions, find tips and tricks, network with other users, and more. Here, you'll find scripting-specific forums for all of the CS3 applications. Search them often, and don't be afraid to post questions of your own. http://www.adobe.com/support/forums/index.html

Until next time, keep scripting!


Ben Waldie is president of Automated Workflows, LLC (www.automatedworkflows.com), a company offering AppleScript, Automator, and workflow consulting services to Mac-based businesses. For years, Ben has developed professional automated solutions for companies such as Abercrombie & Fitch, Adobe Systems, Apple Computer, CNN, Microsoft, PC World, and Time Magazine. Ben is the author of Automator for Mac OS X 10.5 Leopard: Visual QuickStart Guide (Peachpit Press) and AppleScripting the Finder, as well as an AppleScript training CD (VTC). Ben is a frequent presenter at Macworld Expo and other events, and is president of The Philadelphia Area AppleScript Users Group. Ben can be reached by email at ben@automatedworkflows.com

 

Community Search:
MacTech Search:

Software Updates via MacUpdate

Viber 11.7.0 - Send messages and make fr...
Viber lets you send free messages and make free calls to other Viber users, on any device and network, in any country! Viber syncs your contacts, messages and call history with your mobile device, so... Read more
Drive Genius 5.3.1 - $79.00
Drive Genius features a comprehensive Malware Scan. Automate your malware protection. Protect your investment from any threat. The Malware Scan is part of the automated DrivePulse utility. DrivePulse... Read more
CorelDRAW 21.2.0.708 - Graphic design so...
CorelDRAW - professional graphic design software for vector illustration, layout, and so much more. Get started quickly and easily with a wealth of intuitive tools, built-in learning materials,... Read more
Navicat Premium Essentials 12.1.27 - Pro...
Navicat Premium Essentials is a compact version of Navicat which provides basic and necessary features you will need to perform simple administration on a database. It supports the latest features... Read more
OmniFocus 3.4.3 - GTD task manager with...
OmniFocus is an organizer app. It uses projects to organize tasks naturally, and then add tags to organize across projects. Easily enter tasks when you’re on the go, and process them when you have... Read more
Microsoft OneNote 16.30 - Free digital n...
OneNote is your very own digital notebook. With OneNote, you can capture that flash of genius, that moment of inspiration, or that list of errands that's too important to forget. Whether you're at... Read more
Apple Configurator 2.11.1 - Configure an...
Apple Configurator makes it easy to deploy iPad, iPhone, iPod touch, and Apple TV devices in your school or business. Use Apple Configurator to quickly configure large numbers of devices connected to... Read more
Luminar 3.1.4 - Powerful, adaptive, conf...
Luminar is the new full-featured image editor that adapts to the way you edit photos. Over 300 essential tools to fix, edit, and enhance your photos with comfort. The future of photo editing is here... Read more
SketchUp 19.3.252 - Create 3D design con...
SketchUp is an easy-to-learn 3D modeling program that enables you to explore the world in 3D. With just a few simple tools, you can create 3D models of houses, sheds, decks, home additions,... Read more
VirtualBox 6.0.14 - x86 virtualization s...
VirtualBox is a family of powerful x86 virtualization products for enterprise as well as home use. Not only is VirtualBox an extremely feature rich, high performance product for enterprise customers... Read more

Latest Forum Discussions

See All

Breakout: Dark Prison is a fast-paced ac...
Breakout: Dark Prison is an action RPG from LaterSoft. Set in the aftermath of a deadly virus outbreak your daughter has been taken from you because she has an immunity to the illness in her DNA. Not being a fan of experimentation on children –... | Read more »
Apple Arcade in review
This weekend, Apple Arcade will officially be one month old. That means anyone who signed up for the free trial on day one has a decision to make: Stick with the service and shell out $5 a month, or cancel and go about your merry way. | Read more »
Alluris is a choose-your-own adventure g...
Alluris is an RPG that the developer's are calling a swipe-your-own adventure game. This is because the game incorporates a Reigns-style - swiping left or right - selection mechanic to make all the decisions you'd usually expect to make across... | Read more »
Hello Hero All Stars receives update wit...
The first Hello Hero game hit global platforms in 2013 and proved a huge success, with developer Fincon adding two more entries to this popular series of casual RPG games since. Released in June this year, Hello Hero All Stars brings many of the... | Read more »
Zombieland: Double Tapper, a cartoon idl...
Zombieland: Double Tapper is the idle RPG tie-in to the upcoming Zombieland: Double Tap. Oddly, it's one of two different Zombieland games launching today, with the other being the Switch title Zombieland: Double Tap - Road Trip. [Read more] | Read more »
Rusty Lake's The White Door launche...
Rusty Lake and Second Maze's intriguing point-and-click adventure game, The White Door, is now up for pre-order on the App Store. This one sees you playing as Robert Hill, a mental health patient who is suffering from severe memory loss. The game... | Read more »
Hellrule is an auto-runner inspired by G...
Hellrule is an upcoming auto-runner game from independent developer Pedrocorp where players will take control of a dapperly dressed gentlemen who comes equipped with a razor-sharp umbrella for slicing up his foes. The game will be available for... | Read more »
Grobo is a gravity bending puzzle platfo...
Grobo is a 2D puzzle platformer that marks the first release from developers Hot Chocolate Games. You'll find yourself manipulating gravity as you make your through this title that's available now for iOS and Android. [Read more] | Read more »
Adrenaline, Compulsive Entertainment’s h...
Compulsive Entertainment’s high-octane arcade racer, Adrenaline, has now made its way to the App Store following a successful launch on Google Play. It’s a ton of challenging, fast-paced fun, boasting easy-to-learn controls and a varied selection... | Read more »
Mario Kart Tour is adding Super Mario Ga...
Earlier today on Twitter, Nintendo announced that Mario Kart Tour is getting a new racer and track. Fans of Super Mario Galaxy will be pleased to hear that Rosalina is the first post-launch character being added, while the iconic Rainbow Road is... | Read more »

Price Scanner via MacPrices.net

Verizon offers free iPhone 7 for customers wh...
Verizon is offering a free 32GB iPhone 7 for new or existing customers who open a new line of service, no trade-in required. Cost of the phone is credited to your account monthly for 24 months. The... Read more
13″ 2.4GHz 4-Core MacBook Pros remain availab...
Apple has a full line of Certified Refurbished 2019 13″ 2.4GHz 4-Core Touch Bar MacBook Pros available starting at $1529 and up to $300 off MSRP. Apple’s one-year warranty is included, shipping is... Read more
Lease one iPhone Xs, Xr, or X at Sprint and g...
Purchase an Apple iPhone X, Xr, Xs, or Xs Max at Sprint, and get a 64GB iPhone Xr for free. Requires 2 new lines or 1 upgrade-eligible line and 1 new line. The fine print: “iPhone Xs (64 GB) $37.50/... Read more
How to use your Apple Education discount to s...
Purchase a new MacBook Pro or MacBook Air using Apple’s Education discount, and take up to $200 off MSRP. All teachers, students, and staff of any educational institution with a .edu email address... Read more
Base 2019 13″ 1.4GHz 4-Core MacBook Pro on sa...
Amazon has the new 2019 13″ 1.4GHz/128GB 4-Core Space Gray Touch Bar MacBook Pro on sale for $100 off Apple’s MSRP. This is the same MacBook Pro sold by Apple in its retail and online stores: – 2019... Read more
Save up to $30 on Apple’s AirPods at these re...
Amazon is offering discounts on new 2019 Apple AirPods ranging up to $30 off MSRP. Shipping is free: – AirPods with Charging Case: $144 $15 off MSRP – AirPods with Wireless Charging Case: $169 $30... Read more
Save $15 on Apple Watch Series 5 models on Wa...
Walmart has new Apple Watch Series 5 models on sale for $15 off Apple’s MSRP on their online store. Choose free shipping or free local store pickup (if available). Sale prices for online orders only... Read more
Save $750 on the base 8-Core 27″ iMac Pro wit...
Apple has Certified Refurbished 27″ 3.2GHz 8-Core iMac Pros available for $4249 including free shipping. Their price is $750 off the cost of new models. A standard Apple one-year warranty is included... Read more
Apple continues to offer 11″ iPad Pros, refur...
Apple has Certified Refurbished 11″ iPad Pros available on their online store for up to $220 off the cost of new models. Prices start at $679. Each iPad comes with a standard Apple one-year warranty... Read more
Get Beats Solo3 Wireless Headphones today for...
Amazon has Beats Solo3 Wireless On-Ear Headphones in stock and on sale today for $139.99 shipped. Their price is $60 off Apple’s MSRP, and it’s the lowest price available for this model from any of... Read more

Jobs Board

Best Buy *Apple* Computing Master - Best Bu...
**741528BR** **Job Title:** Best Buy Apple Computing Master / Wheaton **Job Category:** Store Associates **Location Number:** 001129-Wheaton-Store **Job Read more
Best Buy *Apple* Computing Master - Best Bu...
**738529BR** **Job Title:** Best Buy Apple Computing Master **Job Category:** Sales **Location Number:** 000258-Lewisville-Store **Job Description:** **What does a Read more
*Apple* Device Support - Kelly Services (Uni...
…including iPads, iPhones, iPods etc. You will be supporting and troubleshooting all Apple mobile devices in a corporate environment. If you are interested please Read more
Best Buy *Apple* Computing Master - Best Bu...
**730598BR** **Job Title:** Best Buy Apple Computing Master **Job Category:** Store Associates **Location Number:** 001129-Wheaton-Store **Job Description:** The Read more
Best Buy *Apple* Computing Master - Best Bu...
**741153BR** **Job Title:** Best Buy Apple Computing Master **Job Category:** Sales **Location Number:** 000411-Flint-Store **Job Description:** **What does a Best Read more
All contents are Copyright 1984-2011 by Xplain Corporation. All rights reserved. Theme designed by Icreon.