You can make a difference in the Apple Support Community!

When you sign up with your Apple Account, you can provide valuable feedback to other community members by upvoting helpful replies and User Tips.

Looks like no one’s replied in a while. To start the conversation again, simply ask a new question.

Album Locator

I used this script that I copied from the communities and it no longer seems to be working. I wonder if someone can tell me how to get it working again. I found it to be an indispensable part of Photos for me with over 18,000 photos placed in 97 albums. I am using a iMac running Catalina. I used to just click on the photo and the script in my dropdown menu and it showed me the album. Now it says it cannot. See below for result and the printout of the script I am using. These codes and scripting have no meaning to me. Thank you for any assistance you might give.



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

iMac Line (2012 and Later)

Posted on Jan 28, 2021 3:59 PM

Reply
Question marked as Top-ranking reply

Posted on Jan 29, 2021 4:05 AM

Did you just recently upgrade to Catalina? Then the script needs updating. I published an updated version here:


How to find out the albums a photo is in:… - Apple Community


Catalina has broken some support for scripting Photos. Elegant lines like these for example do no longer work:

 set theseNames to name of (albums whose id of media items contains thisId)


We now have to search recursively through all albums and folders.

When you try the updated version of the script, it will only work, if you select the photo in All Photos or a top level album, and also not in a smart album.


I can no longer test on Catalina, because I upgraded all Catalina Macs from Catalina to Big Sur, which improved the iCloud Syncing. But the modified script is working well for me on Big Sur.


Similar questions

3 replies
Question marked as Top-ranking reply

Jan 29, 2021 4:05 AM in response to sburech

Did you just recently upgrade to Catalina? Then the script needs updating. I published an updated version here:


How to find out the albums a photo is in:… - Apple Community


Catalina has broken some support for scripting Photos. Elegant lines like these for example do no longer work:

 set theseNames to name of (albums whose id of media items contains thisId)


We now have to search recursively through all albums and folders.

When you try the updated version of the script, it will only work, if you select the photo in All Photos or a top level album, and also not in a smart album.


I can no longer test on Catalina, because I upgraded all Catalina Macs from Catalina to Big Sur, which improved the iCloud Syncing. But the modified script is working well for me on Big Sur.


Jan 29, 2021 9:48 AM in response to xsedna

I've compiled the latest script into an application and posted it this tutorial page: P01 - Applescripts from Photos’ User Tips Compiled as Applications


Go to that page and download Item #10. When you first run it Control (right) - click on it and select Open from the contextual menu. Be sure to select the photo before launching the app.


It words for me in Big Sur.


Jan 29, 2021 4:37 AM in response to sburech

Hello,


the very nice script itself still works!

However, in Catalina the Photos App database has been rewritten from scratch and unfortunately -as léonie already wrote- the album search now only works in albums on the top level (as it still does in macOS 11).


The error, however, comes from a bug that arose in this context (which is fixed in macOS 11) :

As you can see in your screenshot, you are in a Smart Folder. In Catalina, photos that are selected in a Smart Folder cannot be found with AppleScript.


To summarize:

You will only find photos that are in a top level album and they cannot be selected in Smart Folders.



To extend the search back to all albums, no matter what level they are in, I wrote an app that recursively searches all albums for a previously selected photo. This takes a bit longer, but works in Catalina (but not with Smart Folder either).

If you want to try it: since I'm not a verified developer, the app has to be opened a bit awkwardly on first launch to bypass Gatekeeper. Explained in the ReadMe


Photos-GetAlbumsOfSelection

Album Locator

Welcome to Apple Support Community
A forum where Apple customers help each other with their products. Get started with your Apple Account.