How can I see in which albums is a photo?
Solution 1:
You can't, at least not out of the box. But there is an AppleScript described in https://robservatory.com/show-albums-a-given-photos-photo-has-been-added-to/ (or actually in https://discussions.apple.com/docs/DOC-9261) which solves the problem, kind of.
To use the script, paste it all into AppleScript Editor and save it as an application (or you can just run it in AppleScript Editor). In Photos, create a top-level album (I named mine Find Albums Photo Is In), and place the photo you want to know about into that album. Leave it selected, then run the AppleScript. You’ll see one dialog stating what photo is being used, then after a bit, you should see a results dialog
-- from https://robservatory.com/show-albums-a-given-photos-photo-has-been-added-to/
tell application "Photos"
activate
-- Add the photo you want to search for to a top level album as the first item in the album
set resultcaption to "Searching for: "
try
set sel to selection
if sel is {} then error "The selection is empty" -- no selection
on error errTexttwo number errNumtwo
display dialog "No photos selected " & errNumtwo & return & errTexttwo
return
end try
set imagename to "unknown filename"
try
set target to item 1 of sel -- the image to seach for
tell target
set imagename to the filename of target
end tell
on error errTexttwo number errNumtwo
display dialog "Cannot get the filename of the first image: " & errNumtwo & return & errTexttwo
end try
set resultcaption to (resultcaption & imagename)
end tell
try
display alert resultcaption buttons {"Cancel", "OK"} as informational giving up after 2
on error errText number errNum
if (errNum is equal to -128) then
-- User cancelled.
return
end if
end try
-- From Jacques Rioux's script:
tell application "Photos"
-- set sel to selection
if sel is {} then return -- no selection
try
set thisId to id of item 1 of sel
on error errText number errNum
display dialog "Error: cannot get the image ID" & errNum & return & errText & "Trying again"
try
delay 2
set thisId to id of item 1 of sel
on error errTexttwo number errNumtwo
display dialog "Skipping image due to repeated error: " & errNumtwo & return & errTexttwo
error "giving up"
return
end try --second attempt
end try
set theseNames to {}
try
set theseNames to name of (albums whose id of media items contains thisId)
on error errText number errNum
display dialog "Error: cannot get the albums" & errNum & return & errText & "Trying again"
try
delay 2
set theseNames to name of (albums whose id of media items contains thisId)
on error errTexttwo number errNumtwo
display dialog "Skipping image due to repeated error: " & errNumtwo & return & errTexttwo
error "giving up"
return
end try
end try
end tell
if theseNames is not {} then
set {oTid, text item delimiters} to {text item delimiters, return}
set {t, text item delimiters} to {theseNames as string, oTid}
-- return oTid
else
set t to "No album"
end if
activate
set resultcaption to resultcaption & ", found it in these albums:
" & t as string
set the clipboard to resultcaption
display dialog resultcaption buttons {"OK"} default button "OK" -- you can press the Enter key or the return Key to close the dialog
return resultcaption -- léonie
Solution 2:
Here's a different Applescript that I wrote, which works for me. With this you can just select a photo in Photos and run the script, without adding the photo to a new album. I saved it in the scripts folder Photos, so it shows up as a menu item in Photos.
tell application "Photos"
set selectedPhotos to get selection -- Get the selected photo
try
if selectedPhotos is {} then error -- No selection
on error
display alert "Select a photo, then run this script to find albums containing the photo."
return
end try
-- Find albums that contain the photo's ID
set selectedPhotoId to get id of first item in selectedPhotos
set containingAlbums to get albums whose id of media items contains selectedPhotoId
try
if containingAlbums is {} then error
on error
display alert "That photo is not in any albums"
end try
-- Get names of albums and show them
set albumNames to name of albums whose id of media items contains selectedPhotoId
set AppleScript's text item delimiters to ", "
albumNames as string
display alert "Albums containing selected photo: " & (albumNames as string)
end tell
Solution 3:
Thanks Tom for your script. It's work, but the script didn't check albums in folders. Do you know how we can add this in the script ?
I have only found how to list the folders in Photos App : set folderNames to name of folders display alert "List of Folders: " & (folderNames as string)
Thanks