Adding Numeric Callout Images
If your work involves creating documentation, you’ll appreciate this set of scripts for automating the process of adding numeric callouts to an image.
The “Add Callout Layer” script displays the contents of your folder containing the callout images in a file picker dialog. Select an image from the picker and it will be placed in a new layer in the currently open Pixelmator image. The other provided scripts will automate the scaling of the selected callout layer, and the reordering of the selected callout layers alphabetically.
DO THIS ► | DOWNLOAD a zip archive (84mb) containing the Pixelmator example images, and the folder of example AppleScript script files. Place the folder of callout images named “Callouts” in the Shared folder (Users > Shared). Put the folder of script named “Numeric Callouts” in the Pixelmator Scripts folder. |
The AppleScript Scripts
Here are the AppleScript scripts that automates the process of importing the callout images, scaling them, and re-ordering the selected callout layers by name.
use AppleScript version "2.4" -- Yosemite (10.10) or later
use scripting additions
property folderName : "Callouts"
property sourceDirectory : path to "sdat" -- Shared folder
(* path to pictures folder *)
(* path to documents folder *)
(* path to public folder *)
set imagesFolderHFSpath to (sourceDirectory as string) & folderName
tell application id "com.pixelmatorteam.pixelmator.x"
activate
try
if not (exists document 1) then error number -128
set imagesFolder to imagesFolderHFSPath as alias
set chosenImageFile to choose file of type "public.image" with prompt "Select image to import:" default location imagesFolder
set imageFileInfo to the info for chosenImageFile
set nameExtenstion to the name extension of the imageFileInfo
set chosenImageFileName to the displayed name of the imageFileInfo
set layerName to text 1 thru -((length of nameExtenstion) + 2) of chosenImageFileName
tell front document
make new image layer with properties {file:chosenImageFile, preserve transparency:true, constrain proportions:false, name:layerName}
end tell
on error errorMessage number errorNumber
if errorNumber is not -128 then
display alert (errorNumber as string) message errorMessage
end if
end try
end tell
use AppleScript version "2.4" -- Yosemite (10.10) or later
use scripting additions
tell application id "com.pixelmatorteam.pixelmator.x"
activate
try
if not (exists document 1) then error number -128
tell front document
tell current layer of it
set height to (height div 2)
set width to (width div 2)
end tell
end tell
on error errorMessage number errorNumber
if errorNumber is not -128 then
display alert (errorNumber as string) message errorMessage
end if
end try
end tell
use AppleScript version "2.4" -- Yosemite (10.10) or later
use framework "Foundation"
use scripting additions
tell application id "com.pixelmatorteam.pixelmator.x"
activate
try
if not (exists document 1) then error number -128
tell front document
set selectedLayers to the selected layers of it
if selectedLayers is {} then error "Please select the layers to rearrange by name."
set layerNames to {}
repeat with i from 1 to the count of selectedLayers
set the end of layerNames to the name of item i of selectedLayers
end repeat
set sortedLayerNames to my sortListOfStrings(layerNames)
set sortedLayerNames to the reverse of sortedLayerNames
repeat with i from 1 to the count of sortedLayerNames
set thisLayerName to item i of sortedLayerNames
set thisLayer to layer thisLayerName
move thisLayer to before layer 1
end repeat
end tell
on error errorMessage number errorNumber
if errorNumber is not -128 then
display alert (errorNumber as string) message errorMessage
end if
end try
end tell
on sortListOfStrings(sourceList)
-- sorts a passed AppleScript list of strings
-- create a Cocoa array from the passed AppleScript list
set the CocoaArray to current application's NSArray's arrayWithArray:sourceList
-- sort the Cocoa array
set the sortedItems to CocoaArray's sortedArrayUsingSelector:"localizedStandardCompare:"
-- return the Cocoa array coerced to an AppleScript list
return (sortedItems as list)
end sortListOfStrings