Getting data from Photos.app into Tinderbox

So, we write a script:

(I’ll put the code in text further below). Running the above with both Photos and Tinderbox v9.x open, the result in Tinderbox is this:

Tada! For actual work you’ll want to expand on this but you have the basic data bridge from Photos → Tinderbox. Here I’m renaming a test note. In reality you’d likely add a new child note per source photo. Or you might actually be writing data directly into a blog article not—but that’s getting down into fine detail.

An further obvious consideration is that your dat set will likely be more than one photo so you might want to make a record, i.e. a list of key:value pairs, and a repeat with to unpack on the Tinderbox side, but I’ve leave that to someone with less rusty AppleScript skills to flesh out.

Let\s say you’ve 4 photos in this this turn of the blogging workflow (article, article(s), whatever). for each of the 4 you need 2 bits of info. I’d be tempted to make the photo filename the key (a camera-generated name is generally unique in this context). Then I’d concatenate the title and description with a non-ambigUous divider, e.g “####”. Now you get a single record like:

IMG_2803.HEIC:Tomatillos####Tomatillos freshly harvested from the allotment

Having made the list of records, you’d iterate through, unpack title and description in the record’s value and using those two strings where needed.

Here’s my little text script, to past into the script window in Script Editor:

use AppleScript version "2.4" -- Yosemite (10.10) or later
use scripting additions

tell application "Photos"
	tell its album "Blog"
		tell its media item "Tomatillos"
			set theDescription to description
			set theTitle to name
		end tell
	end tell
end tell

tell application "Tinderbox 9"
	tell note "blog" of front document
		set value of (attribute named "Text") to theDescription
		set value of (attribute named "Name") to theTitle
	end tell
end tell

Security
Note, of late, macOS has—for very good reason—tightened up security as regards which apps/processes can do what. But, as you’ll see below, this comes with some challenges for the occasional scripter.

I’d suggest testing initially from your AppleScript scripting app (Script Editor, Script Debugger, etc.). For that you’ll need to give express permission for that app to be allowed to do automation.

Once the script works from a Scripting environment, you can experiment using with Automator, or Shortcuts, or the menubar’s scripts folder, or as an osascript command line. Whichever you use will need new permissions (these are deliberately granular). However, you make find code that runs in a script editor without problem will fail with unhelpful messages 9or with no message at all) when
run indirectly. Why? I’ve no idea. Worst case you may have to run your script from a script editor, but hopefully not. :slight_smile:

Tip: Before running the scripts, open you System Preferences ▸ Security & Privacy ▸ Privacy tab ▸ select Accessibility in the left-side list. This is where you’ll be asked to add things. Click the padlock (bottom left of the SysPrefs dialog so you’re ready to edit.

Tip: The OS generally gives you a pop-up telling you which needs what. Until you are used to this, don’t rush to click allow as this can fail is your system prefs are locked. Plus some apps/processes require giving permissions to ‘apps’ nested deep in other apps or the OS Library. I find it a good habit to have Sys Prefs open and unlocked (above) tip and to check is the item is already there (but maybe unticked). Also after allowing permission, re-check what got added/enabled. Not least, you might at some point want to turn off permission for and/or delete that app from the list at a later date. Taking a moment to do this the first few times helps build the muscle memory of where to look for the settings.

Tip: If you rush through accepting permissions requests and the process fails, the OS often appears to assume your failure to set access (e.g. you pressed ‘allow’ but had’t unlocked Sys Prefs first) means “don’t allow and never ask me again”. The behaviours is not consistent, so there are obviously further factors in this. But, trying to figure out which obscurely labelled sub-app needs permission and where you even find it can take longer than writing a script.

Sorry for another long post abut I hope that helps with getting data safely from Photos to Tinderbox!

1 Like