The Art of AppleScript

Metadata Meta

Scripting Metadata in Adobe Illustrator

Incorporate metadata from Adobe Illustrator documents in AppleScript Mac Automation Scripting.

Metadata Matters

To add metadata to your Illustrator document, choose File → File Info from Illustrator’s menus and fill-in the following Basic metadata fields:


Metadata in Illustrator is stored as XMP but is more useful if we export it as a JSON database that contains the Basic metadata.

tell application "Adobe Illustrator" activate set theSourceIllustration to the current document set theOutputFolderPath to prepOutputFolder("Output", "") of me exportMetadataFrom(theSourceIllustration, theOutputFolderPath) of me tell application "Finder" to open folder theOutputFolderPath display notification "metadata exported" with title (the name as text) subtitle (my name as text) end tell (* include exportMetadataFrom, makeLowerCaseNoSpaces, makeTextFile, and prepOutputFolder subroutines here *)

Metadata Meat

Reusable subroutines provide the meat of the workflow.

on exportMetadataFrom(theSourceIllustration, theOutputFolderPath) tell application "Adobe Illustrator" set theSourceXMPString to the XMP string of theSourceIllustration tell application "System Events" set theSourceXMPXML to make new XML data with properties {name:"theSourceXMPXML", text:theSourceXMPString} tell theSourceXMPXML's XML element "x:xmpmeta"'s XML element "rdf:RDF"'s XML element "rdf:Description" set theCreatorXML to the first XML element whose name is "dc:creator" set theCreatorValue to theCreatorXML's XML element "rdf:Seq"'s XML element "rdf:li"'s value set theDescriptionXML to the first XML element whose name is "dc:description" set theDescriptionValue to theDescriptionXML's XML element "rdf:Alt"'s XML element "rdf:li"'s value set theSubjectXML to the first XML element whose name is "dc:subject" set theSubjectList to theSubjectXML's XML element "rdf:Bag" set theKeywordsValue to theSubjectList's XML element "rdf:li"'s value repeat with theCounter from 2 to the count of XML elements in theSubjectList set theKeywordsValue to theKeywordsValue & ", " & (XML element theCounter of theSubjectList)'s value end repeat set theRightsXML to the first XML element whose name is "dc:rights" set theRightsValue to theRightsXML's XML element "rdf:Alt"'s XML element "rdf:li"'s value set theTitleXML to the first XML element whose name is "dc:title" set theTitleValue to theTitleXML's XML element "rdf:Alt"'s XML element "rdf:li"'s value end tell end tell set theNameValue to makeLowerCaseNoSpaces(theTitleValue) of me set theOutputJSON to "{ \"author\": " & quote & theCreatorValue & quote & ", \"copyright\": " & quote & theRightsValue & quote & ", \"description\": " & quote & theDescriptionValue & quote & ", \"keywords\": " & quote & theKeywordsValue & quote & ", \"name\": " & quote & theNameValue & quote & ", \"title\": " & quote & theTitleValue & quote & " } " set theOutputJSONPath to theOutputFolderPath & theNameValue & ".json" makeTextFile(theOutputJSONPath, theOutputJSON) of me end tell return end exportMetadataFrom on makeLowerCaseNoSpaces(theSourceText) tell application "BBEdit" set theNoSpacesText to replace " " using "" searchingString theSourceText set theLowerCaseNoSpacesText to theNoSpacesText change case making lower case end tell return theLowerCaseNoSpacesText end makeLowerCaseNoSpaces on makeTextFile(theTextFilePath, theTextFileContents) tell application "BBEdit" activate set theTextFile to make new document with properties {encoding:"Unicode (UTF-8)", text:theTextFileContents} set the line breaks of the front document to Unix select insertion point 1 of the contents of the front document save the front document to file theTextFilePath end tell return end makeTextFile 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

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 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. *)


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.