If you are continually getting error messages with the script you are using, either try if it will work better if you only select the photos in the "All Photos" album.
Or try the second version I posted above. It will change the titles of all photos that are in an album named "PhotoDropBox".
This album needs to be a regular album, not a smart album, and at the top level of the library, not inside a folder.
Copy and paste the complete text below into a Script Editor window, save the script, and press the run button, after you created your album in Photos.
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"