Automation begins with scripting. It is the foundational element that enables the user to query and control applications in OS X, unfettered by the limitations imposed on other forms of application-to-application communication. And best-of-all, because of its built-in scripting support, you can add Photos to your repertoire of automation tools.
Applications that support script access, are said to be “scriptable” and each one includes a user-readable dictionary of all the terms, objects, and commands that can be used by a script to communicate with the application. And like other scriptable applications, Photos has a scripting dictionary you use to create scripted solutions for managing and exporting your image library.
And when it comes to writing scripts, OS X offers two native script-language options for you choose from: AppleScript or JavaScript for Automation (JXA). AppleScript is a well-established and supported English-like language that those new to scripting find to be an approachable automation tool. JavaScript for Automation (JXA), new to OS X, is an extension of the core JavaScript language that those with coding-experience find to be familiar and understandable.
Regardless of which language you prefer, they both interact with the Photos scripting architecture to get the job done!
Here’s an script example that provides a quick way to assign keywords to selected Photos images:
Add Keywords to Selected Photos (AppleScript)
01
-- Script is written using AppleScriptObj-C, so load Cocoa Foundatation framework
02
useframework "Foundation"
03
usescripting additions
04
05
propertykeyWordString : "" -- his property will remember last entry
06
07
tellapplication "Photos"
08
setcurrentSelectionto theselection
09
ifcurrentSelectionis {} then errornumber -28
10
setdialogMessageto "Enter a comma-delimited list of keywords to apply to the selected media items:"
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.