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.

Merge Photos.app albums all containing certain text

Using the latest Photos.app v3.0


I have about 1000 albums that were 'events' in iPhoto and have been converted to 'albums' with the upgrade to Photos.app. I want to reduce these thousands of albums to dozens by regrouping them.


The album title will typically include the name of people in the photos, so a title might be something like "John, Mary, Peter, at beach" and another "Mary, Peter, shopping" or just "baking". With the various combinations of people, locations and activities, it's easy to see how my diligence in album naming has resulted in so many albums.


The actual photo may be devoid of any meaningful tags, titles, file name, or other useful info.


For starters, I want to reduce the albums to just names of specific people, so one album for just John, another for Mary, and yet another for just Peter. How are all the photos whose album includes "John" in the title then selected en masse and moved to a new album?


At best I can only see how to search the Photos library via the top right search field for 'John' which results in hundreds of albums listed. From the found list I can choose only 1 of the albums at a time. Opening any one of them displays the photos in that one album for which I can do 'select all' and drag to the destination album but I don't want have to do this hundreds of times for each destination album.


The 'smart albums' offer no better solution, either, it seems. The 'Album' criteria offers only 'is' (or 'is not') and 'Any' and then specific folder names and album names. I can't see how this could be useful in this case. There's no way find all albums whose title includes a particular text.


I don't want to rely on the face recognition, either. Training it would be too much trouble since it is mostly for children growing up and face changing over time.


Any useful insights, hints, or tips would be appreciated.

iMac, macOS High Sierra (10.13.2)

Posted on Jan 6, 2018 5:26 AM

Reply
Question marked as Top-ranking reply

Posted on Jan 16, 2018 4:10 AM

You could try a script like this:


The script below will do the following:

  • It will ask for string to search for in the album names, for example "John".
  • Then it will create a list of all photos from the albums with "John" in the name.
  • To return the found photos it will create a new album named like the search string you entered and add the photos to this album.
  • You will see the Script Editor bounce in the Dock, when it is done. Click it to open the dialog panel and dismiss it by clicking o.k.


To run the script, open Script Editor. Copy and paste the code below the dashed line into a new Script Editor document and press the run button.

-- ✄ -- ✄ -- -----------------------------------------------------------


-- Select the photo in Photos, then run this script by pressing the "Run" button in the script editor or from the scripts menu.


-- ask for the search string

set SearchFor to text returned of (display dialog "Enter the text to search for in the album name: " default answer "new" buttons {"OK"} default button "OK")


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 albumsFound to (albums whose name contains SearchFor) -- list of all albums with "SearchFor" in the name

set albumNames to name of (albums whose name contains SearchFor)


set photosInMatchingAlbums to {}


repeat with thisAlbum in albumsFound

set theseItems to (the media items of thisAlbum) as list

set photosInMatchingAlbums to photosInMatchingAlbums & theseItems

end repeat


-- return photosInMatchingAlbums --testing


-- create an album with the photos from all albums

try

if not (exists container SearchFor) then


makenewalbumnamedSearchFor

end if

set theSearchForAlbum to containerSearchFor

on error errTexttwonumbererrNumtwo

display dialog "Cannot create new album " & SearchFor & errNumtwo & return & errTexttwo

end try


addphotosInMatchingAlbumstotheSearchForAlbum



end tell



if albumNames is not {} then

set {oTid, text item delimiters} to {text item delimiters, return} --

set {t, text item delimiters} to {albumNames as string, oTid}


-- return oTid

else

set t to "No album"

end if


set resultcaption to "Found " & SearchFor & " in these albums:

" & t & " and created a new Album " & SearchFor as string

set the clipboard toresultcaption-- add the album names to the Clipboard


display dialogresultcaptionbuttons {"OK"} default button "OK" -- you can press the Enter key or the return Key to close the dialog


return resultcaption-- léonie

-- published as a new user tip here: Script: Search for albums with a certain phrase in the name and combine them into a new album

10 replies
Question marked as Top-ranking reply

Jan 16, 2018 4:10 AM in response to Stekor

You could try a script like this:


The script below will do the following:

  • It will ask for string to search for in the album names, for example "John".
  • Then it will create a list of all photos from the albums with "John" in the name.
  • To return the found photos it will create a new album named like the search string you entered and add the photos to this album.
  • You will see the Script Editor bounce in the Dock, when it is done. Click it to open the dialog panel and dismiss it by clicking o.k.


To run the script, open Script Editor. Copy and paste the code below the dashed line into a new Script Editor document and press the run button.

-- ✄ -- ✄ -- -----------------------------------------------------------


-- Select the photo in Photos, then run this script by pressing the "Run" button in the script editor or from the scripts menu.


-- ask for the search string

set SearchFor to text returned of (display dialog "Enter the text to search for in the album name: " default answer "new" buttons {"OK"} default button "OK")


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 albumsFound to (albums whose name contains SearchFor) -- list of all albums with "SearchFor" in the name

set albumNames to name of (albums whose name contains SearchFor)


set photosInMatchingAlbums to {}


repeat with thisAlbum in albumsFound

set theseItems to (the media items of thisAlbum) as list

set photosInMatchingAlbums to photosInMatchingAlbums & theseItems

end repeat


-- return photosInMatchingAlbums --testing


-- create an album with the photos from all albums

try

if not (exists container SearchFor) then


makenewalbumnamedSearchFor

end if

set theSearchForAlbum to containerSearchFor

on error errTexttwonumbererrNumtwo

display dialog "Cannot create new album " & SearchFor & errNumtwo & return & errTexttwo

end try


addphotosInMatchingAlbumstotheSearchForAlbum



end tell



if albumNames is not {} then

set {oTid, text item delimiters} to {text item delimiters, return} --

set {t, text item delimiters} to {albumNames as string, oTid}


-- return oTid

else

set t to "No album"

end if


set resultcaption to "Found " & SearchFor & " in these albums:

" & t & " and created a new Album " & SearchFor as string

set the clipboard toresultcaption-- add the album names to the Clipboard


display dialogresultcaptionbuttons {"OK"} default button "OK" -- you can press the Enter key or the return Key to close the dialog


return resultcaption-- léonie

-- published as a new user tip here: Script: Search for albums with a certain phrase in the name and combine them into a new album

Jan 16, 2018 4:10 AM in response to Stekor

I would rename the destinations albums you already created, so they will not be found when the script is trying to merge the albums.


How large is your library? I tested with a library of 50000 photos and there it worked well.


You could delete the last part of the script - everything after "end tell"

This part is not needed - it will just show the list of albums that have been merged. But it may give a timeout error, if you do not respond to the dialog with the message.


if albumNames is not {} then

set {oTid, text item delimiters} to {text item delimiters, return} --

set {t, text item delimiters} to {albumNames as string, oTid}


-- return oTid

else

set t to "No album"

end if


set resultcaption to "Found " & SearchFor & " in these albums:

" & t & " and created a new Album " & SearchFor as string

set the clipboard toresultcaption-- add the album names to the Clipboard


display dialogresultcaptionbuttons {"OK"} default button "OK" -- you can press the Enter key or the return Key to close the dialog


returnresultcaption-- léonie

Jan 6, 2018 7:23 AM in response to Stekor

The 'smart albums' offer no better solution, either, it seems. The 'Album' criteria offers only 'is' (or 'is not') and 'Any' and then specific folder names and album names. I can't see how this could be useful in this case. There's no way find all albums whose title includes a particular text.

You would have to create a smart album with several "Album is" rules combined by "Any", for example "Album is John at beach" or "Album is John baking"

This would be tedious.


How about using keywords? Open each of your Albums in turn, select all photos, then add the names of the persons as a keyword. Just open the Info panel after you selected all photos in the album, then type each name into the keyword field of the panel. Use the return key after you added each name.


Afterwords you can simply create smart albums based on "keyword is".


To be able to create the albums automatically from the album names, you would have to write an Apple Script, that retrieves a list of album names, finds all album names with "John" in the title, then creates a new album named "John" from all found albums.

Jan 6, 2018 9:27 PM in response to léonie

You would have to create a smart album with several "Album is" rules combined by "Any", for example "Album is John at beach" or "Album is John baking"

This would be tedious.

If I understand this method correctly, each smart album would need to have a list of dozens or hundreds of criteria lines - one for each album with 'John' (for example) in its title. This indeed would be more tedious and difficult than the manual search method I described already. Plus, I suspect I would need more than the maximum number of criteria lines useable in a smart album.


How about using keywords? Open each of your Albums in turn, ...


Thanks but I want to avoid doing this a thousand times. Remember, I have a thousand albums like this.


To be able to create the albums automatically from the album names, you would have to write an Apple Script, that retrieves a list of album names, finds all album names with "John" in the title, then creates a new album named "John" from all found albums.


If that is the only automated way, then so be it. However, I am not familiar with AppleScript. Where do I start to do this? Also, I think the script would need to do things slightly differently from what you wrote. I can easily manually create new album named 'John', but the tricky part is moving into it from elsewhere all the photos who album has 'John' in the title.

Jan 7, 2018 4:58 AM in response to léonie

Thanks for that. I tried it just now twice - first with the name 'Amadeus' and later with 'Trinity' which after about 4 minutes in each case resulted in the error message "error "Photos got an error: AppleEvent timed out." number -1712"


At this point the script text "addphotosInMatchingAlbumstotheSearchForAlbum" was auto selected at this point so presume that's where it stopped.


I already have an album called 'Amadeus' and 'Trinity' in a folder, so don't know if that throws a spanner in the works. The script created a new album at the top of the My Albums list with the 'Amadeus' name. It contains 1396 photos starting from earliest of times to the most recent ones so seems to work well. However, because of the error, I wonder if it has missed any albums or photos.


When I ran it the second time (using 'Trinity') the Photo app remained unresponsive even after the script stopped with the error and a short while later the whole computer became mostly unresponsive. I managed to launch Activity Monitor which revealed most of the apps had become unresponsive. I forced quit Photos, then normality returned.


I re-launched Photos.app and found that the Trinity album was sitting above the Amadeus one, as expected, but it was empty.


I will test this again later but wonder if you have any further tips on using this script.

Jan 7, 2018 10:33 PM in response to léonie

I would rename the destinations albums you already created, so they will not be found when the script is trying to merge the albums.


I ensured all albums were uniquely named and ran it again for Amadeus, but the same error resulted. I was wrong about the timing: it is only 2 or 3 minutes before it appears. Like last time, even after dismissing the error message in Script Editor, Photos.app continued to be unresponsive and missing the new album for another 5 or more minutes before showing the new Amadeus album. The number of photos it holds is the same each time: 1396.


How large is your library? I tested with a library of 50000 photos and there it worked well.


The library has almost 41,000 photos.


You could delete the last part of the script - everything after "end tell"

This part is not needed - it will just show the list of albums that have been merged. But it may give a timeout error, if you do not respond to the dialog with the message.


I tried that and the same error results. In fact, that error probably explains why the script never shows the list of albums that have been merged: It's crashing before it get's to any dialog to respond to.


Is it possible that the time-out error is due to Photos.app encountering a corrupt or invalid 'photo' in its library? I recall that I was troubleshooting an iPhoto-to-Photos library migration months back for someone else which consistently failed. Investigation showed bitmap clip art was in the source library which caused the migration to fail. Presumably iPhoto didn't mind the bitmap files but Photos.app did. Removing the offending files from the source library allowed the migration to work.


I've since tried it several times with different names and the result is almost consistent. Error occurs in Script Editor after 2 or 3 minutes which I dismiss at which point the Script Editor's last line "addphotosInMatchingAlbumstotheSearchForAlbum" is auto-selected. Then Photo.app is unresponsive for a while longer, then the new (filled) album is shown and normality returns. In cases where there are only a few hundred photos, the error does not occur.


If the error is benign, that's OK, but how do I find that out?


When Photos.app returns to normal, the Console log displays something like: -

"10759711: Error #17 (os/kern) invalid right attempting to add send right to port ( port:230971/0x3863b rcv:0,send:0,d:3 limit:0)."


The numbers (underlined) immediately after the port and slash differ with each error, but the rest is the same. I don't see anything else in the Console log that is likely relevant. When the error is displayed the Console log outputs: -

"[ERROR] - Unknown CGXDisplayDevice: 0x41dc9d00"


(I am using an additional monitor attached to my iMac, but I can't see that Script Editor error message is related to the monitor setup)

Jan 7, 2018 11:37 PM in response to Stekor

Is it possible that the time-out error is due to Photos.app encountering a corrupt or invalid 'photo' in its library?

This is unlikely, because the script is not trying to open the photos or videos, just trying to add them to an album. Do you have items in your Photos Library, that are neither photos nor videos, but audio files or similar? Does the status line at the bottom view show "Items" in addition to videos and photos?


The script might fail, if your Photos library has a corruption and needs repairing, for example because of permission errors in the library. Is your library an optimized iCloud Photo Library? Is the library on an external drive with a file system, that is not MacOS Extended (Journaled), as it should be? Is the drive perhaps formatted case-sensitive?


Have you tested with the external monitor disconnected?

Jan 8, 2018 3:54 AM in response to léonie

Do you have items in your Photos Library, that are neither photos nor videos, but audio files or similar?


I don't think so. But there are some old AVI video files which have become corrupt and won't open. Photos.app reports 'Photos cannot play this video because the resource is unavailable' when I attempt to play within the Photos app.


There are about 725 AVI files and a random check suggests most probably won't play nor export.


Are they possibly the error cause? If so, I'll remove them, but it would be tedious to to identify the bad ones for removal among the 725.


Does the status line at the bottom view show "Items" in addition to videos and photos?


The bottom edge of the Script Editor window just shows the same as what the error message was. "Photos got an error: AppleEvent timed out." Is that what you are referring to?


The script might fail, if your Photos library has a corruption and needs repairing, for example because of permission errors in the library. Is your library an optimized iCloud Photo Library? Is the library on an external drive with a file system, that is not MacOS Extended (Journaled), as it should be? Is the drive perhaps formatted case-sensitive?


If corruption includes the AVI files that won't open, then I guess I have to remove them after all and then retry. I have run the library repair (via Option command keys on Photos.app launch) since this issue started and the errors still occur despite that. I don't use iCloud Photo so presumably it's not optimised for that. Would that potentially help or hinder? The library is in the default home folder in the Pictures folder on the default internal boot drive which is Mac OS Extended (Journaled). - Not case-sensitive.


Have you tested with the external monitor disconnected?


Yes, and it makes no difference to the Script Editor results nor to the Console log output which still lists the same types of errors.


Apart from the errors I get, I think the script you provided is great. Thanks. Was it easy for you?

Jan 8, 2018 5:06 AM in response to Stekor

Apple Script looks easy, but the syntax is not intuitive. I have frequently to look up the syntax, so it takes an hour or so to write a new script.



Does the status line at the bottom view show "Items" in addition to videos and photos?


The bottom edge of the Script Editor window just shows the same as what the error message was. "Photos got an error: AppleEvent timed out." Is that what you are referring to?

I meant the status line in Photos, at the bottom of the Photos window, when the Photos album is selected in the sidebar.

Does this show "Items" in addition to photos and videos?

Jan 16, 2018 4:08 AM in response to léonie

re: status line info

I can't see any info at the bottom edge of the Photos.app window when Photos is chosen at left in the sidebar just under the category of Library. I can't see any way of making any 'status' line appear, either - even if other things are chosen in the sidebar.


However, if I invoke the Info window via Window menu > Info, and select Photos in the sidebar, then, among other things, it displays 38,940 Photos, 1,934 Videos and straight under that 232.61 GB. There is no mention of anything else.


The start of the date range above all of that is likely wrong because it is 1901-12-14 but I guess that's probably irrelevant.

Merge Photos.app albums all containing certain text

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