Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Save webdevotion/be499c822901cf7a46035454b9321b9e to your computer and use it in GitHub Desktop.
Save webdevotion/be499c822901cf7a46035454b9321b9e to your computer and use it in GitHub Desktop.
Applescript for Pixelmator Pro documents to export all layers in nested folders as images files.
on list2string(theList, theDelimiter)
-- First, we store in a variable the current delimiter to restore it later
set theBackup to AppleScript's text item delimiters
-- Set the new delimiter
set AppleScript's text item delimiters to theDelimiter
-- Perform the conversion
set theString to theList as string
-- Restore the original delimiter
set AppleScript's text item delimiters to theBackup
return theString
end list2string
on traverse(myLayer, exportLocation)
tell application "Pixelmator Pro"
set visible of myLayer to true
if ((class of myLayer as text) = "group layer") then
set mySubLayers to (every layer of myLayer)
repeat with sublayer in mySubLayers
if ((class of sublayer as text) = "group layer") then
my traverse(sublayer, exportLocation)
else
my layerToExport(sublayer, exportLocation)
end if
end repeat
else
my layerToExport(myLayer, exportLocation)
end if
end tell
end traverse
on layerToExport(myLayer, exportLocation)
tell application "Pixelmator Pro"
set p to myLayer
set pathComponents to {}
repeat while p exists
set visible of p to true
set s to (name of p as text)
set beginning of the pathComponents to s
set p to parent of p
end repeat
set prefix to my list2string(pathComponents, "_")
set filename to prefix & ".jpg"
set visible of myLayer to true
export for web the front document to file ((exportLocation as text) & filename) as JPEG with properties {compression factor:100}
set visible of myLayer to false
set p to myLayer
repeat while p exists
set visible of p to false
set p to parent of p
end repeat
end tell
end layerToExport
tell application "Pixelmator Pro"
set exportLocation to choose folder with prompt "Please choose where you'd like to export the images:"
tell the front document
set visible of every layer to true
repeat with currentLayer in every layer
my traverse(currentLayer, exportLocation)
end repeat
set visible of every layer to true
end tell
display notification " images have been successfully exported." with title "Pixelmator Pro"
end tell
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment