The Art of AppleScript

Command Illustrator Exports

Custom File Export Menu Commands for Adobe Illustrator

Use Adobe Illustrator and AppleScript Mac Automation Scripting to create custom menu commands for Illustrator that export multiple images to your exact specifications including file system location in one quick and easy step every time.

Command Illustrator

By creating our own custom file export menu command for Illustrator, we can change the export process from interactive form-filling to one where Illustrator essentially reads the details it needs for each export out of our own written file specifications. You can create just one file export menu command that is customized perfectly to the way you work, or you can create dozens of file export menu commands, each customized to a particular project or type of work output.

We can create custom menu commands for Illustrator using AppleScript, Script Editor, and Script Menu, all of which are built into every Mac. Write the AppleScript code for your menu command in Script Editor and Save the command into Illustrator’s script folder.

To run your command within Illustrator, launch Script Menu. When Illustrator is the frontmost application, Script Menu will show the contents of Illustrator’s script folder.

SVG Specification

A list of the values for SVG export options defines a specification for your Illustrator SVG output.

export the current Illustrator document as a standalone SVG: - with the source name - width: 100% - height: 100% - to the folder ~/Output/

The problem with this output specification is that only humans can understand it. But if we translate the specification into AppleScript, it can be read by humans and Illustrator.

tell application "Adobe Illustrator" activate (* set the output folder to ~/Output/ *) set theOutputFolderPath to prepOutputFolder("Output", "") of me (* export SVG with the source name, width: 100%, height: 100%, and to the output folder *) illustratorExportSVG("", "", "", theOutputFolderPath) of me (* when all image files are exported *) tell application "Finder" to open folder theOutputFolderPath display notification "image files exported" with title (the name as text) subtitle (my name as text) end tell (* include illustratorExportSVG and prepOutputFolder subroutines here *)

Filling in Details

Although Illustrator can understand an output specification that’s written in AppleScript, it will need a decoder ring of sorts — in the form of subroutines — that fill in a bunch of details it needs to turn the specification into action. The subroutines are reused every time you export files, no matter what the specification.

You may want to write your own file export subroutines, or you may want to use my subroutines under MIT License. Paste the following code block at the end of an AppleScript in Script Editor to make the subroutines available within that AppleScript.

on illustratorExportSVG(theFileName, thePixelWidth, thePixelHeight, theOutputFolderPath) tell application "Adobe Illustrator" set theSourceDocument to the current document set theFileExtension to ".svg" if thePixelWidth is equal to "" then set thePixelWidth to "100%" end if if thePixelHeight is equal to "" then set thePixelHeight to "100%" end if if theFileName is equal to "" then set theFullFileName to the name of theSourceDocument set AppleScript's text item delimiters to "." set theFileName to the first text item of theFullFileName set AppleScript's text item delimiters to "" end if set theExportFilename to theOutputFolderPath & theFileName & theFileExtension export theSourceDocument to file theExportFilename as SVG with options {artboard range:"", coordinate precision:3, CSS properties:style attributes, font type:SVG font, minify svg:false, responsive svg:true, save multiple artboards:false} end tell return end illustratorExportSVG on prepOutputFolder(theOutputFolderName, theSubFolderName) tell application "Finder" set theHomeFolderPath to the path to the home folder as text set theHomeFolder to theHomeFolderPath as alias set theOutputFolderPath to theHomeFolderPath & theOutputFolderName & ":" if not (exists folder theOutputFolderPath) then set theOutputFolder to make new folder at theHomeFolder with properties {name:theOutputFolderName} else set theOutputFolder to theOutputFolderPath as alias end if if theSubFolderName is equal to "" then set theTargetFolderPath to theOutputFolderPath else set theSubFolderPath to theHomeFolderPath & theOutputFolderName & ":" & theSubFolderName & ":" set theTargetFolderPath to theSubFolderPath if not (exists folder theSubFolderPath) then set theSubFolder to make new folder at theOutputFolder with properties {name:theSubFolderName} else set theSubFolder to theSubFolderPath as alias end if end if end tell return theTargetFolderPath end prepOutputFolder

Work with Multiple Source Files in One Step

To work with multiple source files in one step, wrap export commands in an open block and Save your AppleScript as a Mac application, which will create an AppleScript droplet. Drop source image files on the droplet for processing in Illustrator.

Within the droplet script we repeat through multiple files, processing them one at a time in Illustrator. We also need to use multiple output folders to avoid output files with the same name simply overwriting each other as each new file is processed. Here we sort output files into subfolders named for the folders that contain the source images.

(* when files are dropped on an application made from this script *) on open theFiles tell application "Adobe Illustrator" activate repeat with theFile in theFiles -- to come close the current document saving no end repeat (* when all image files are exported *) tell application "Finder" to open folder theOutputFolderPath display notification "image files exported" with title (the name as text) subtitle (my name as text) end tell end open (* include illustratorExportSVG and prepOutputFolder subroutines here *)

Example Scripts

AppleScripts made from the example code on this page.

Code Reuse

The blocks of example code on this page and the attached example scripts are open source software that everyone can use and modify and customize for their own purposes under MIT License.

(* Copyright 2015 Simon White http://simonwhite.com/ MIT License Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions: The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software. THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. *)

Author

Simon White

Last updated .


Keywords: artist, animator, designer-developer, agile, agile-developer, agile-development, full-stack, developer, coder, graphic-artist, web-animator, illustrator, adobe-illustrator, photoshop, adobe-photoshop, vector-graphics, raster-graphics, pixel-graphics, bitmap-graphics, wacom, mac, macintosh, apple-mac, unix, animation, artwork, code, digital-pen, digital-pencil, digital-ink, hand-drawn, hand-coded, handmade, interactive, html, svg, animated-svg, html5, css3, es5, unobtrusive-javascript, dom-scripting, responsive-animations, responsive-layouts, w3c, iso, audio, classlist, cssanimations, csstransforms, csstransitions, eventlistener, inlinesvg, json, opacity, preserve3d, queryselector, requestanimationframe, rgba, webaudio, xhrresponsetypejson.