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

Photos Utility Script Library

Script Libraries

The scripting support built into the Photos application is designed to provide users with the means for automating specific functions and tasks, both simple and complex.

And to make it possible to create automation scripts with simpler and less scripting code, the Photos Utilities script library is comprised of suites of scripting commands designed to augment the existing scripting support in the Photos application in creative and powerful ways.

Some of the script library’s published commands are shortcuts for dealing with common Photos items like folder and albums, while other commands make the process of exporting images to disk or into iWork documents, as simple as writing a single line of script code.

And even though the Photos Utilities script library is written using the super-powerful AppleScriptObj-C (see sidebar), it can be referenced and called from within scripts written in either of the native scripting languages of OS X: AppleScript or JavaScript for Automation (JXA)

NOTE: The Photos Utilities script library requires the installation of OS X v10.11 El Capitan or newer.

Installing the Script Library

To install this script library:

  • DOWNLOAD and unpack the zip archive containing the script library file. (v1.2)
  • Place the script library bundle file into the Script Libraries folder located within the user’s Library folder (if there is no Script Libraries folder, then add one).

Using the Library with AppleScript

When using the library with AppleScript, insert the following loading statement at the top of any AppleScript scripts that will be incorporating commands from this library:

use script "Photos Utilities"

Once the library has been installed in the user’s Library folder, and referenced at the beginning of the script, you can use the library’s commands throughout the script, like this:

Export Selection to Files (AppleScript)
  
01use script "Photos Utilities"
02 
03tell application "Photos"
04 set theseItems to (get the selection)
05 quick export of theseItems with resulting file references and Finder reveal
06end tell

Using the Library with JavaScript for Automation (JXA)

And here’s a version of the same script written in JavaScript for Automation (JXA). Note that the JXA script stores a reference to the script library in a standard JavaScript variable, like this:

var PhotosUtilities = Library("Photos Utilities")

Export Selection to Files (JavaScript for Automation - JXA)
  
01var Photos = Application("Photos")
02var PhotosUtilities = Library("Photos Utilities")
03 
04var items = Photos.selection()
05 
06PhotosUtilities.quickExport({
07 of: items,
08 resultingFileReferences: true,
09 finderReveal: true
10})

Begin exploration of the various library commands by examining the Photos Utility Suite (link below).

NEXT TOPIC: Photos Utility 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.