Question about using Shortcuts (or Automator) app with Photos app [cross posting]
[I originally posted an earlier version of this in the MacOS Monterey group & they suggested I post it here.]
Goal: I would like to create a script that can look at a photo in the Photos app, determine if the "Title" field is empty, and if so, copy the "Filename" field into the "Title" field. (Ideally it would be able to do this with a batch of photos without Titles, or recursively.)
I was pointed to the following AppleScript which I managed to plug into Automator, and it seemed to work but with an odd (& unsatisfactory) result (described below):
on run {input, parameters}
tell application "Photos"
activate
set imageSel to (get selection)
if imageSel is {} then
error "Please select an image."
else
repeat with im in imageSel
set title to the name of im
if not (exists (title)) then
set the name of im to the filename of im
end if
end repeat
end if
end tell
end run
So I managed to run this script in Automator [as a "Workflow" because I couldn't find the option to run it as a "Service" (I'm using MacOS 12.1)] but had a weird result. It appears to work OK, except that after it runs, in the Library window the title still appears gray, like nothing changed. The "Get Info" window shows something in the Title field (which wasn't there before running the script). BUT, when I click on the title area under the photo, it goes blank (as it does on a photo that hasn't been renamed) and then the next time I click on the photo's thumbnail, the Get Info window has lost its Title and once again says (in italics) "Add a Title." I exited Photos and relaunched it, and this weird behavior continued.
So the script does appear to change the title (it looks correct in the Get Info window at first) but it's very "fragile," disappearing as soon as I click in the title field under the thumbnail. Bizarre!
Ideas?
MacBook Air (2020 or later)