Batch copy/synchronize Titles and Captions in MacOS Photos
Now that the Photos app in iOS allows editing captions on the iPhone, I faced a conundrum: the captions I entered on the iPhone weren't visible in Photos on the Mac (except by opening the image info pane), and the titles I've entered in Photos on the Mac for my thousands of pictures weren't visible on the iPhone.
I started with Léonie's script for batch changing titles to captions, then modified it so that:
- If a photo has a Title but no Caption, the Title is copied to the Caption. This makes it visible in iOS apps.
- If a photo has a Caption but no Title, the Caption is copied to the Title. This makes it visible in Photos on the Mac.
- If a photo has both a Title AND a Description, both are left as is.
- If a photo has NEITHER a Title nor a Description, nothing happens.
Finally, I used the modified script in a Quick Action in Automator, as described in JML54's post, so that the script can be run from Photos' Services menu.
Here is the full script. Hope someone else finds this helpful.
-- This script works with the Photos app to copy text between the Title and Description fields of each photo.
-- If a photo has a Title but no Description, the Title is copied to the Description. This makes it visible in iOS apps.
-- If a photo has a Description but no Title, the Description is copied to the Title. This makes it visible in Photos on the Mac.
-- If a photo has both a Title AND a Description, both are left as is.
-- If a photo has NEITHER a Title nor a Description, nothing happens.
-- To use, select one or more photos then run this script.
-- Based on https://discussions-cn-prz.apple.com/en/docs/DOC-250003341
set imageSel to {}
set separator to " - "
set imagesProcessed to 0
set imageDescriptionsCopied to 0
set imageTitlesCopied to 0
tell application "Photos"
activate
try
set imageSel to (get selection)
on error errTexttwo number errNumtwo
display dialog "Cannot get the selection: " & errNumtwo & return & errTexttwo
end try
if imageSel is {} then
error "Please select some images."
else
repeat with im in imageSel
set newTitle to ""
-- get the description of the image if it exists
set newTitle to (the description of im) --as string
set hasDescription to (newTitle is not equal to missing value) and (the length of newTitle > 0)
set currentTitle to ""
-- get the title of the image if it exists
set currentTitle to (the name of im)
set hasTitle to (currentTitle is not equal to missing value) and (the length of currentTitle > 0)
set imagesProcessed to (imagesProcessed + 1)
if hasDescription and not hasTitle then -- copy Description to Title
try
tell im
set its name to newTitle
end tell
on error errText number errNum
display dialog "Error: " & errNum & return & errText & "Trying again"
try
delay 2
tell im
set its name to newTitle
end tell
on error errTexttwo number errNumtwo
display dialog "Skipping copying image description to title due to repeated error: " & errNumtwo & return & errTexttwo
end try
end try
set imageDescriptionsCopied to (imageDescriptionsCopied + 1)
end if
if not hasDescription and hasTitle then -- copy Title to Description
try
tell im
set its description to currentTitle
end tell
on error errText number errNum
display dialog "Error: " & errNum & return & errText & "Trying again"
try
delay 2
tell im
set its description to currentTitle
end tell
on error errTexttwo number errNumtwo
display dialog "Skipping copying image title to description due to repeated error: " & errNumtwo & return & errTexttwo
end try
end try
set imageTitlesCopied to (imageTitlesCopied + 1)
end if
end repeat
end if
end tell
tell application "Script Editor"
activate
end tell
display dialog "Done: " & imagesProcessed & " photos processed; " & imageDescriptionsCopied & " Captions copied to Titles; " & imageTitlesCopied & " Titles copied to Captions."
MacBook Pro 15″, macOS 11.6