The Art of AppleScript

The Made and the Saved

Automate the Making and Saving of Adobe Photoshop Documents

Use AppleScript Mac Automation Scripting and Adobe Photoshop to customize and automate the making and saving of new Photoshop documents.

Begin the Begin

Photoshop can create a wide variety of image documents with a wide variety of properties and features. Customizing the way that we make new documents with Photoshop enables us to call up exactly the new document we want, with exactly the right properties and features, all in one step.

Making a Layered Canvas

tell application "Adobe Photoshop CC 2017" activate make new document repeat 3 times make new art layer in the current document with properties {visible:true} end repeat end tell

Sizing the Canvas

Resizing the canvas is a natural next step. There are an essentially infinite number of sizes but you are probably only using a few most of the time. Choosing from your own custom list of your favorite sizes is generally quick and easy, but you may also have various contexts such as screen or print work.

Rather than have just one resize canvas command or one set of templates, we can use AppleScript to create multiple commands, each for a specific context.

Resize Canvas to Video Size

When you are working with video and you have to resize the canvas for whatever reason, then a resize canvas command that knows all the video sizes relieves you of the burden of knowing them all.

tell application "Adobe Photoshop CC 2017" activate if the current document exists then set theCurrentDocument to a reference to the current document set theVideoCanvasSizes to {"240×135 pixels", "480×270 pixels", "960×540 pixels", "1920×1080 pixels HDTV", "3840×2160 pixels 4KTV", "7680×4320 pixels 8KTV"} set theCanvasSize to photoshopChooseFromList("Please choose a canvas size.", theVideoCanvasSizes) of me photoshopResizeCanvas(theCurrentDocument, theCanvasSize) of me set theCompletionMessage to "canvas resized to" & space & theCanvasSize else set theCompletionMessage to "please open a document before resizing" end if display notification theCompletionMessage with title (the name as text) subtitle (my name as text) end tell (* include photoshopResizeCanvas and photoshopChooseFromList subroutines here *)

Resize Canvas to Print Size

We can duplicate and subtly rewrite our Resize Canvas to Video Size script and teach the new script some common print sizes.

tell application "Adobe Photoshop CC 2017" activate if the current document exists then set theCurrentDocument to a reference to the current document set thePrintCanvasSizes to {"3.5×2 inches Business Card", "3×5 inches Index Card", "5×5 inches CD", "8.5×11 inches Letter Paper", "8.5×14 inches Legal Paper", "11×17 inches Tabloid Paper", "12×12 inches LP", "24×24 inches Art Print"} set theCanvasSize to photoshopChooseFromList("Please choose a canvas size.", thePrintCanvasSizes) of me photoshopResizeCanvas(theCurrentDocument, theCanvasSize) of me set theCompletionMessage to "canvas resized to" & space & theCanvasSize else set theCompletionMessage to "please open a document before resizing" end if display notification theCompletionMessage with title (the name as text) subtitle (my name as text) end tell (* include photoshopResizeCanvas and photoshopChooseFromList subroutines here *)

Resize Canvas to Favorite Size

Instead of a list of standard sizes, you can create a command that knows some of the sizes that you use the most. For some of us, the list might be a couple of ad banner sizes, a couple of video sizes, and a couple of print sizes.

To create a custom script that knows your own particular favorites, simply modify the list of canvas sizes in the following script until it represents your own personal favorites.

tell application "Adobe Photoshop CC 2017" activate if the current document exists then set theCurrentDocument to a reference to the current document set theFavoriteCanvasSizes to {"300×48 pixels Smartphone Banner", "468×60 pixels Full Banner", "1920×1080 pixels HDTV", "3840×2160 pixels 4KTV", "12×12 inches LP", "24×24 inches Art Print"} set theCanvasSize to photoshopChooseFromList("Please choose a canvas size.", theFavoriteCanvasSizes) of me photoshopResizeCanvas(theCurrentDocument, theCanvasSize) of me set theCompletionMessage to "canvas resized to" & space & theCanvasSize else set theCompletionMessage to "please open a document before resizing" end if display notification theCompletionMessage with title (the name as text) subtitle (my name as text) end tell (* include photoshopResizeCanvas and photoshopChooseFromList subroutines here *)

Scaling the Canvas for Pixel Ratios

to come

Saving the Canvas

Finally, we must Save our new document so that we minimize the chance of losing our work. This requires Photoshop to show us a dialog box asking for a name for the file.

tell application "Adobe Photoshop CC 2017" -- to come end tell

Save with Automatic Backup

to come

Routine the Routine

Reusable subroutines provide functionality without coding.

on photoshopResizeCanvas(theTargetDocument, theCanvasSize) tell application "Adobe Photoshop CC 2017" if theCanvasSize is not equal to false then set theSavedRulerUnits to the ruler units of the settings set AppleScript's text item delimiters to space set theCanvasMeasurement to the first text item of theCanvasSize set theCanvasUnits to the second text item of theCanvasSize set AppleScript's text item delimiters to "×" set theCanvasWidth to the first text item of theCanvasMeasurement as number set theCanvasHeight to the second text item of theCanvasMeasurement as number set AppleScript's text item delimiters to "" if theCanvasUnits is equal to "inches" then set the ruler units of the settings to inch units else set the ruler units of the settings to pixel units end if resize canvas theTargetDocument width theCanvasWidth height theCanvasHeight anchor position middle center set the ruler units of the settings to theSavedRulerUnits end if end tell return end photoshopResizeCanvas on photoshopChooseFromList(theChoicePrompt, theChoices) tell application "Adobe Photoshop CC 2017" activate try choose from list theChoices with title (the name as text) with prompt theChoicePrompt without multiple selections allowed and empty selection allowed set theChoice to the result as text on error theErrorMessage set theChoice to false end try end tell return theChoice end photoshopChooseFromList

A 3-act Story

We can combine the above making, resizing, and saving scripts into one script that enables us to do all of that in one step, so that we can go from the intention to make artwork to everything setup to make artwork by running one script from the Script Menu in Photoshop.

Setup for Painting

There is always a technical hurdle for setting up art tools and media for painting, but if your canvas is digital, it can setup itself.

tell application "Adobe Photoshop CC 2017" -- to come end tell (* include photoshopResizeCanvas and photoshopChooseFromList 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 2005 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.