Are you using iCloud Photo Library? Then the script will not work well with Photos. The problem is the line "get selection".
Photos selected this way may give timeout errors.
I just updated the user tip, so it uses the work-around for this problem proposed by NicFletcher: Don't ask for the current selection, but add the photos you want to process to an album with a fixed name.
- Create an album with a fixed name - mycurrentselection or similar - and add all photos you want to process to this album.
- Instead of the "get current selection" process the photos in this album.
-- batch change the title of images to the filename
(* How to use this script:
Open this script in Script Editor. Launch Photos.
The photos can be passed to the script in two ways:
1. Either select photos while viewing the "All Photos" album; this works better than Moments or smart albums
2. Or collect the Photos in a top level defined album with a fixed name.
If you want to select the photos without collecting them in an album, set the variable "ReadFromAlbum" to false
If you want to pass the photos in a toplevel album, set ReadFromAlbum to true and change the variable "theAlbumName" to the name of the album you are using.
When all all photo are selected or in the album and all parameters set, press the "Run" button in Scripteditor.
*)
set ReadFromAlbum to true
-- set this to true, if you want to pass the photos in a toplevel album
set theAlbumName to "PhotoDropBox" -- change this to the name of the album you will use
set imageSel to {}
tell application "Photos"
activate
if (ReadFromAlbum) then -- the photos will be passed in a toplevel album named "PhotoDropBox"
try
if existscontainertheAlbumName then
set thePhotosBuffer to containertheAlbumName
set imageSel to every media item of thePhotosBuffer
else
error "Album " & theAlbumName & "does not exist"
end if
on error errTexttwonumbererrNumtwo
display dialog "Cannot open album: " & errNumtwo & return & errTexttwo
end try
else -- process the selected photos from the All Photos album
try
set imageSel to (get selection)
on error errTexttwonumbererrNumtwo
display dialog "Cannot get the selection: " & errNumtwo & return & errTexttwo
end try
end if
-- check, if the album or the selected photos do contain images
if imageSel is {} then
error "Please select some images."
else
repeat with im in imageSel
try
tell im
set its name to its filename
end tell
on error errText number errNum
display dialog "Error: " & errNum & return & errText & "Trying again"
try
delay 2
tell im
set its name to its filename
end tell
on error errTexttwonumbererrNumtwo
display dialog "Skipping image due to repeated error: " & errNumtwo & return & errTexttwo
end try
end try
end repeat
end if
end tell
-- display dialog "Done"
return "Done"