photos-applescript-banner
•
OS X AUTOMATION
AUTOMATOR
IWORK AUTOMATION
•

Photos Export Suite

One of the most often performed tasks in Photos is the export of images. The Photos Export suite of the Photos Utilities script library reduces the multi-step process involved with exporting photos to images files, into single-line commands, each designed to achieve a specific type of export.

During the export process, every one of the export commands creates a uniquely-named folder within the user’s Pictures folder, in which the exported files are placed. The created destination folders are named with a date string in the same manner as screen shots are titled by OS X:

Photos Export 2015-09-11 at 07.57.10 AM

In addition, some of the commands offer the option to display in the Finder, either the destination folder or its contents after the export process has completed.

Also note that, with the exception of the export originals command, all commands export photos to files in high-quality JPEG format.

quick export v  : Exports copies of the referenced media items to a newly created folder within the Pictures folder. All image exports are in high-quality JPEG format.

quick export

of object reference(s) : References to the media item(s) to export

[ ID as name boolean ] : A boolean value indicating whether the exported files should be named using the IDs of their source images. Default value is false. Ex: npAZ8eBtR8+rBbsvhRWiIg.jpg

[ resulting file references boolean ] : A boolean value indicating whether the command should return as its result, a list of references to the exported files. If the value is false, the command result will be a reference to the created export folder. Default value is true.

[ Finder reveal boolean ] : A boolean value indicating whether the export results (files or folder) should be revealed in the Finder. Default value is false.

→ folder reference|list of file references : Depending on the value of the “resulting file references” parameter, the result can be a reference to the output folder, or a list of references to the exported files.

 

export originals v  : Exports copies of the orignial masters of the referenced media items to a newly created folder within the Pictures folder.

export originals

of object reference : References to the media items to export

[ resulting file references boolean ] : A boolean value indicating whether the command should return as its result, a list of references to the exported files. If the value is false, the command result will be a reference to the created export folder. Default value is true.

[ Finder reveal boolean ] : A boolean value indicating whether the export results (files or folder) should be revealed in the Finder. Default value is false.

→ folder reference|list of file references : Depending on the value of the “resulting file references” parameter, the result can be a reference to the output folder, or a list of references to the exported files.

 

sequentially named export v  : Exports copies of the referenced media items, named sequentially, to a newly created folder within the Pictures folder. EX: Vacation-001.jpg, Vacation-002.jpg, etc. All image exports are in high-quality JPEG format.

sequentially named export

of object reference : References to the media items to export

[ base name text ] : The base name to use for the sequenced exported files.

[ separator text ] : The text used to separate the base name from the numeric sequence. Default is a space.

[ sequence length integer ] : The minimum length of the numeric sequence. Leading zeros will be added, if needed, to match the minimum length (length of 4 = 0001, 0002, etc.). For no leading zeros, set the value to 1. If the parameter is not used, the default value is automatically determined to match the count of input items.

[ starting number integer ] : The number to begin the naming sequence. Default is 1.

[ resulting file references boolean ] : A boolean value indicating whether the command should return as its result, a list of references to the exported files. If the value is false, the command result will be a reference to the created export folder. Default value is true.

[ Finder reveal boolean ] : A boolean value indicating whether the export results (files or folder) should be revealed in the Finder. Default value is false.

→ folder reference|list of file references : Depending on the value of the “resulting file references” parameter, the result can be a reference to the output folder, or a list of references to the exported files.

 

export to Keynote v  : Exports copies of the referenced media items, and imports them into the current slide in the frontmost Keynote document. If no document is open in Keynote, one will be created using the current Keynote defaults.

export to Keynote

using object reference : References to the media items to export

[ new document from template named text ] : If this optional parameter is included, a new Keynote document will be created using the named template. To invoke the default template, set the parameter’s value to be an empty string: ""

[ document dimensions list of integers ] : A comma-delimited list of two integers describing the width and height (in points) of the new document. EX: {1024, 768}. Values for built-in sizes: Standard = {1024, 768} Wide = {1920, 1080}

[ new slide for each boolean ] : A boolean value indicating whether a new slide should be created for each exported photo. Default value is true.

→ slide reference(s) : References to the newly created slides in the Keynote document

 

export to Numbers v  : Exports copies of the referenced media items, and imports them into the active in the frontmost Numbers document. If no document is open in Numbers, one will be created using the current Numbers defaults.

export to Numbers

using object reference : References to the media items to export

[ new document from template named text ] : If this optional parameter is included, a new Numbers document will be created using the named template. To invoke the default template, set the parameter’s value to be an empty string: ""

→ image reference(s) : References to the newly created images in the Numbers document

 

export to Pages v  : Exports copies of the referenced media items, and imports them into the current page in the frontmost Pages document. If no document is open in Pages, one will be created using the current Pages defaults.

export to Pages

using object reference : References to the media items to export

[ new document from template named text ] : If this optional parameter is included, a new Pages document will be created using the named template. To invoke the default template, set the parameter’s value to be an empty string: ""

→ image reference(s) : References to the newly created images in the Pages document

Script Examples

The following scripts demonstrate the use of the commands in the Photos Export Suite.

Quick Export
  
01use script "Photos Utilities"
02 
03tell application "Photos"
04 set thesePhotos to get the selection
05 if thesePhotos is {} then error number -128
06 set exportDirectory to quick export of thesePhotos with Finder reveal
07end tell
Export Originals
  
01use script "Photos Utilities"
02 
03tell application "Photos"
04 set thesePhotos to get the selection
05 if thesePhotos is {} then error number -128
06 set exportedFiles to ¬
07 export originals of thesePhotos with resulting file references and Finder reveal
08end tell
Sequentially Named Export
  
01use script "Photos Utilities"
02use scripting additions
03 
04tell application "Photos"
05 set thesePhotos to get the selection
06 if thesePhotos is {} then error number -128
07 display dialog "Enter the base name for the exported files:" default answer ""
08 set baseName to the text returned of the result
09 if baseName is "" then set baseName to "Untitled"
10 set exportedFiles to ¬
11 sequentially named export of thesePhotos sequence length 3 ¬
12 with resulting file references and Finder reveal
13end tell

NOTE: The commands for exporting to iWork documents all export Photos images to files and then imports the exported files into the iWork documents. After the iWork import process has completed, the folder containing the exported images is moved to the trash.

Export to Keynote
  
01use script "Photos Utilities"
02 
03tell application "Photos"
04 set thesePhotos to get the selection
05 if thesePhotos is {} then error number -128
06 set addedSlides to ¬
07 export to Keynote using thesePhotos ¬
08 new document from template named "Gradient" document dimensions {1024, 768} ¬
09 with new slide for each
10end tell
Export to Numbers
  
01use script "Photos Utilities"
02 
03tell application "Photos"
04 set thesePhotos to get the selection
05 if thesePhotos is {} then error number -128
06 set addedImages to export to Numbers using thesePhotos
07end tell
Export to Pages
  
01use script "Photos Utilities"
02 
03tell application "Photos"
04 set thesePhotos to get the selection
05 if thesePhotos is {} then error number -128
06 set addedImages to export to Pages using thesePhotos ¬
07 new document from template named "Blank Landscape"
08end tell

Videos

The Export to Keynote command used in a Dictation Workflow:

Your browser does not support the video tag.

The quick export command used in two Dictation Workflows:

Your browser does not support the video tag.

The Export to Numbers command used in a Dictation Workflow:

Your browser does not support the video tag.

NEXT TOPIC: Photos Extras Suite

TOPICS

  • Automator Overview

  • Scripting Overview
  • Photos Script Library
  • Photos Utility Suite
  • Photos Export Suite
  • Photos Extras Suite

ABOUT SCRIPT LIBRARY

For those interested in creating and writing scripts and script libraries, the Photos Utilities Script Library is written in AppleScriptObj-C, a dynamic fusion of the AppleScript and Objective-C programming languages. The source code of the library can be viewed in a script editing application.

Comprehensive 3rd-party documentation and tools for writing and deploying AppleScriptObj-C applications, scripts, and script libraries are available from Myriad Communications.

LINK TO MYRIAD COMMUNICATIONS WEBSITE

DISCLAIMER

THIS WEBSITE IS NOT HOSTED BY APPLE INC.

Mention of third-party websites and products is for informational purposes only and constitutes neither an endorsement nor a recommendation. PHOTOSAUTOMATION.COM assumes no responsibility with regard to the selection, performance or use of information or products found at third-party websites. PHOTOSAUTOMATION.COM provides this only as a convenience to our users. PHOTOSAUTOMATION.COM has not tested the information found on these sites and makes no representations regarding its accuracy or reliability. There are risks inherent in the use of any information or products found on the Internet, and PHOTOSAUTOMATION.COM assumes no responsibility in this regard. Please understand that a third-party site is independent from PHOTOSAUTOMATION.COM and that PHOTOSAUTOMATION.COM has no control over the content on that website. Please contact the vendor for additional information.