As some of you might know Illustrator doesn’t have the handy batch-options that PhotoShop has. So if you have a bunch of Illustrator files and you want to perform an action on all of them, you’re stuck with opening them one by one…
Well, as I mentioned in my previous article, you can create macro’s for any given program with AppleScript. So why not use this handy feature to perform batch actions in Illustrator? In this article, I’ll explain how you can use AppleScript to do just this.
Opening the Illustrator files in a batch
Well, the first thing we need to do of course, is get a list of files we would like to open. Let’s say we want to perform a batch action on a folder containing Illustrator files. In AppleScript you can create a list with files like so:
1 2 3 |
tell application "Finder" set theFiles to files of folder POSIX file "/Users/Giel/Desktop/my illustrator files" as alias list end tell |
Now we can perform a simple repeat -loop on this list in which we can perform our action:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 |
repeat with f in theFiles # Open the file in Illustrator: tell application "Adobe Illustrator" activate open f # Perform one or more actions here # Save the document # You can optionally set options while saving: save current document with options {PDF compatible:false} close current document end tell end repeat |
Performing one or more actions
We now have a basic skeleton of our Illustrator batch function. Now it’s time to actually execute an action prior for saving. In the above code, replace the comment # Perform one or more action here with something like this:
1 |
do script "Scale to 39.5 height" from "Default Actions" |
Where of course you put the name of your own action you wish to perform. Of course, since it’s a script, there is no limit to the number of actions you can put here. So you’re not limited to one action.
More than just actions
AppleScript isn’t restricted to just actions. There is a lot of other Illustrator stuff you can put here. For example, the following code unlocks all layers and page items in Illustrator:
1 2 3 4 5 6 |
# Set a reference to the current document: set thisDoc to current document # Unlock everything: set locked of every layer of thisDoc to false --unlock all layers set locked of every page item of thisDoc to false --unlock any page items |
It’s also possible to select an item (for example, when for your action a specific element needs to be selected):
1 2 3 4 5 6 |
# Select the correct page item: set pi to page item ("border") of layer ("Layer 1") of thisDoc set the selection to pi # Execute an action: do script "My custom border action" from "Default Actions" |
And that’s just a small fragment of what’s possible. If you want to know all possibilities, I would suggest you take a look at Adobe’s AppleScript scripting reference guide for AppleScript.
Wrap it all up
To wrap it all up, you now have an AppleScript that looks something like this:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 |
on run # Set the files: tell application "Finder" set theFiles to files of folder POSIX file "/Users/Giel/Desktop/my illustrator files" as alias list end tell repeat with f in theFiles # Open the file in Illustrator: tell application "Adobe Illustrator" activate open f # Set a reference to the current document: set thisDoc to current document # Unlock everything: set locked of every layer of thisDoc to false --unlock all layers set locked of every page item of thisDoc to false --unlock any page items # Select the correct page item: set pi to page item ("border") of layer ("Layer 1") of thisDoc set the selection to pi # Execute an action: do script "My custom border action" from "Default Actions" # Save the document # You can optionally set options while saving: save current document with options {PDF compatible:false} close current document end tell end repeat end run |
And that’s it! This little script can be your timesaver for some of your bigger Illustrator projects. Just imagine you relaxing and drinking coffee while you let your Mac crunch those numbers for you. Your co-workers won’t know what hit them! You’ll be the coolest kid on the block!
Visitors give this article an average rating of 4.6 out of 5.
How would you rate this article?
★ ★ ★ ★ ★
I would like create a script so that it performs the following
I should open a file and unlock all layer, delete any hidden layers, select all and convert to outlines. Now i should execute the package in the file menu and save the file, both as ai and pdf.
Can you please help me out.