At the last meet-up, @dmrogers (I hope I tagged the right guy!) was describing† problems getting photo data out of Apple’s Photos.app into Tinderbox. Most pertinently, a photo’s title and caption (description): Photos’ on-screen terminology for these is title
and caption
.
Context note: here, I’m using Tinderbox v9.2.1, on macOS 12.4.0 with Photos v7.0
Above (be aware I’m a novice at using Photos) I added a title and description in Photos. Depending on your digital workflow, these could have been added to (embedded in) the image by some upstream app (camera, Lightroom, etc., etc.)
Challenge: can we get a an images title & caption out of Photos using scripting?
It turns out we can. Looking at and Discarding Apple automation apps in reverse order of triviality of functionality, both Shortcuts.app and its macOS predecessor Automator.app came up blank in terms of ‘canned’ functions to do this. Next stop AppleScript proper, long neglected by Apple but still a useful avenue for automation. Apple provides Script Editor.app (in the ~/Applications/Utilities/
folder), though here I’ve used the rather more powerful (but not free) AppleScript Debugger‡. A nifty feature is the ability to explore an app’s ‘dictionary’§:
We see above that what we think of as a photo is a media item
, which exposes a list of metadata including:
description
. The item’s description.filename
. The name of the stored data file, i.e. the photo’s OS disk filename
. The item’s title [sic].
Note the inconsistent naming between front-of-house (‘name’) and back-of-house (‘title’) that can occur in AppleScript dictionaries. This design laziness often requires the user to resort to text export of fields just to be able to build a consistent terminology map.
Also in the above, is that the photo is in an Album called ‘blog’. This isn’t built-in. Past experience suggests we’ll needed easy way to find just the photos needed, so I added a smart Album ‘blog’¶
Again, Script Debugger’s Explorer tool lets me look at open app’s data. Here is the photo I showed above:
Now we can scrip. I’ll start a new post as this is quite long already…
†. See Meetup: Tinderbox and History (11 June 2022) on Vimeo c1:21:08–1:26.25
‡. Another wonderful long-lived tool in the world of Mac indie apps. Overkill if you don’t need it but excellent if you need a bit more info on what’s going on.
§. Apart from very top-level aspect like app windows, how (if!) you can script within an app is in the gift of the developer who writes/codes the app’s ‘dictionary’ which essentially defines what things are called in code and how to address then: indeed, what subset of app functioning to can address at all.
¶. My album looks for the tag (in Photos, a ‘keyword’) called ‘blog’, but that side of the set-up is left to the user. The point is to make it easy for your script to fine (only) the right items in your Photos app. If you are able to re-use tags, or pre-existing album/Projects in your workflow that’s even better!