Skip to content

Instantly share code, notes, and snippets.

@YOCKOW
Last active February 1, 2021 08:13
Show Gist options
  • Save YOCKOW/2025b52a2fce3f01e92f48be2c44fa5a to your computer and use it in GitHub Desktop.
Save YOCKOW/2025b52a2fce3f01e92f48be2c44fa5a to your computer and use it in GitHub Desktop.
Workaround for a bug of Photos App about setting location.
(*
Workaround for a bug of Photos App about setting location.
Original thread:
"when I enter a location for a picture, Photos changes it to a different location"
https://discussions.apple.com/thread/251905264
See also:
https://discussions.apple.com/thread/251905264?answerId=254499375022#254499375022
https://discussions.apple.com/thread/251905264?answerId=254501019022#254501019022
Contributors:
YOCKOW https://discussions.apple.com/profile/YOCKOW
Stephan-S https://discussions.apple.com/profile/Stephan-S
*)
tell application "Photos"
activate
try
set selectedImages to (get selection)
set numberOfImages to (count of selectedImages)
set imagesDescription to ""
if numberOfImages ≤ 0 then
error "Please select an image."
else if numberOfImages = 1 then
set imageTitle to the name of first item of selectedImages
if (not (exists (imageTitle))) or (imageTitle is "") then
set imageTitle to the filename of first item of selectedImages
end if
set imagesDescription to "\"" & (imageTitle as string) & "\""
else
set imagesDescription to numberOfImages & " images"
end if
set dialogMessage to ("New location for " & imagesDescription & ":")
set response to display dialog dialogMessage default answer "" buttons {"Cancel", "OK"} default button "OK" with icon note
set newLocationString to text returned of response
if ((button returned of response) = "OK") and (newLocationString is not "") then
set AppleScript's text item delimiters to ","
set latitudeLongitude to every text item of newLocationString
if (count of latitudeLongitude) is not 2 then
error "Invalid Location."
end if
repeat with theImage in selectedImages
set the location of theImage to latitudeLongitude
end repeat
display alert "New location set to: " & newLocationString
end if
on error errorMsg number errorNumber
display alert errorMsg as critical
end try
end tell
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment