Script: Batch Change the Description to the Title plus the Current Description (Caption)
In Photos for Mac we can display the titles of a photo below the thumbnails, and the title will be displayed, when we are viewing a photo enlarged. But we cannot see the titles on our iOS devices (iPhone, iPad), when we are syncing the photos with iCloud to the iOS devices and are viewing the photos there. There are third-party apps, that can show us the metadata of a photo, and some of them like Photo Investigator can show us the description of the photo rather than the title. Apple announced at the WWDC 2020, that future versions of iOS and iPadOS will allow us to display the captions (descriptions) of a photo. So we will need the information about a photo in two places, in the title (on the Mac) and in the description/caption on the iPhone and iPad.
Below is a script, that will copy the title of selected photos to the description, followed by an optional suffix, and append the existing description. To run the script, select the photos in a top level album (not in an album nested in a folder) click the run button.
------- copy the script starting form here -------------
(* Version 2 - I removed a few duplicate lines, that could case the error message "Cannot get the selection *)
(* This script copies the title of photos to the description field, in front of any existing description.
You can append an additional comment to the description.
The script will prompt you for an additional text. This is optional and defaults to ""
To run the script, select at least one photo in a top level album or in All Photos.
You can select and batch change several photos at once.
But do not select the photos in a smart album or an album in a folder.
This script is useful, if you are viewing your photos in applications, that can show the caption but not the title.
Author: Léonie 2020
*)
set newDescriptionSuffix to text returned of (display dialog "Enter the new caption: " default answer "" buttons {"OK"} default button "OK")
set withSuffix to (the length of newDescriptionSuffix > 0)
set imageSel to {}
set separator to " - "
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
-- get the title of the image if it exists
set newDescription to ""
-- start the new description with the title
set imTitle to (the name of im) --as string
set hasTitle to (imTitle is not equal to missing value) and (the length of imTitle > 0)
if hasTitle then
set newDescription to imTitle as string
end if
-- get the description of the image if it exists and append it to the title
set oldDescription to (the description of im) --as string
set hasDescription to (oldDescription is not equal to missing value) and (the length of oldDescription > 0)
if (the length of newDescription > 0) then -- is a separator needed?
set theLink to separator
else
set theLink to ""
end if
if (hasDescription) then
-- image has a description, append old description with a separator to the title
set newDescription to newDescription & theLink & oldDescription as string
end if
-- append the suffix to the title
if (the length of newDescription > 0) then -- is a separator needed?
set theLink to separator
else
set theLink to ""
end if
if withSuffix then
set newDescription to newDescription & theLink & newDescriptionSuffix
end if
try
tell im
set the description to newDescription
end tell
on error errText number errNum
display dialog "Error: " & errNum & return & errText & "Trying again"
try
delay 2
tell im
set the description to newDescription
end tell
on error errTexttwo number errNumtwo
display dialog "Skipping image due to repeated error: " & errNumtwo & return & errTexttwo
end try
end try
spotlight im
end repeat
end if
end tell
-- display dialog "Done"
return newDescription