Script: Find Photos not in Any Album, for Photos 5 on Catalina
In the earlier versions of Photos we can easily identify the photos, that are not in any album, by creating a smart album with the rule "Album > is not > Any". this does not work any longer in Photos 5 on Catalina, if photos have been in an album and the album has been deleted, without removing the photos from the album.
In such a case we could for photos not in any album with an Apple Script.
Select the photos in Photos (in the all photos album), then run this script by pressing the "Run" button in the Script Editor or run it from the scripts menu.
The script will create three albums to return the result:
- __NotInAnyAlbum : the album to collect the photos not in any album
- __inAlbum: the album to collect the photos in an album
- __skippedAlbum: for photos that could nit be checked due to error (not yet implemented)
Erase these albums after each run, or the next run will show all photos as being in an album.
-- copy the script from here: -------------------✃ ---✃
-- This cript uses some code from Jacques Rioux's script https://discussions.apple.com/message/29601534#29601534
-- modified by leonie for splitting albums on Catalina
-- version 1 for Photos 5 on macOS 10.15.5
-- Select the photos in Photos (in the all photos album), then run this script
-- by pressing the "Run" button in the script editor
-- or run it from the scripts menu.
--
-- The script will create three albums to return the result:
-- __NotInAnyAlbum : the album to collect the photos not in any album
-- __inAlbum: the album to collect the photos in an album
-- __skippedAlbum: for photos that could nit be checked due to error (not yet implemented)
-- Erase these albums after each run, or the next run will show all photos in an album
global allalbums -- the list of all albums
global allfolders -- the list of all folders
-- part 1. set up the result albums
set notInAlbumName to "__NotInAnyAlbum" -- the album to collect the photos not in any album
set inAlbumName to "__inAlbum" -- the album to collect the photos in an album
set SkippedName to "__skippedAlbum" -- the album to collect the photos causing errors
set inAlbumList to {}
set notinAlbumList to {}
set skippedList to {}
tell application "Photos" --tell 1
activate
-- Ensure that the albums do exist
try
if not (exists container notInAlbumName) then
make new album named notInAlbumName
end if
set notInAlbum to container notInAlbumName
if not (exists container inAlbumName) then
make new album named inAlbumName
end if
set inAlbum to container inAlbumName
if not (exists container SkippedName) then
make new album named SkippedName
end if
set skippedAlbum to container SkippedName
on error errTexttwo number errNumtwo
display dialog "Cannot open albums: " & errNumtwo & return & errTexttwo
end try
end tell -- 1
--part 2. get the selected photos
tell application "Photos" --tell 2
activate
-- Add the photo you want to search for to a top level album as the first item in the album
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
end tell --2
-- Part 3: get a list of all albums by searching the nested folders
set allfolders to {}
set allalbums to {}
tell application "Photos"
set allalbums to the albums -- collect all albums
set allfoldernames to {}
set allalbumnames to {}
set level to 0 -- nesting level of folders
set nextlevelFolders to the folders
set currentLevelFolders to {}
repeat while (nextlevelFolders is not {})
set currentLevelFolders to nextlevelFolders
set nextlevelFolders to {}
repeat with fi in currentLevelFolders
tell fi
set ffolders to its folders
set falbums to its albums
set nextlevelFolders to ffolders & nextlevelFolders
set allalbums to falbums & allalbums
end tell
end repeat
set allfolders to currentLevelFolders & allfolders
set level to level + 1
end repeat
-- return allalbums --test
end tell
-- From Jacques Rioux's script:
tell application "Photos"
if sel is {} then return -- no selection
repeat with im in sel
try
set thisId to id of im
on error errText number errNum
display dialog "Error: cannot get the image ID" & errNum & return & errText & "Trying again"
try
delay 1
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 {}
repeat with a in allalbums
try
tell a
if ((the id of media items) contains thisId) then
set theseNames to {the name of a} & theseNames
end if
end tell
--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 1
tell a
if ((the id of media items) contains thisId) then
set theseNames to {the name of a} & theseNames
end if
end tell
on error errTexttwo number errNumtwo
display dialog "Skipping image due to repeated error: " & errNumtwo & return & errTexttwo
-- set skippedList to {im} & skippedList
error "giving up"
return
end try
end try
end repeat
if theseNames is not {} then
set inAlbumList to {im} & inAlbumList
else
set notinAlbumList to {im} & notinAlbumList
end if
end repeat
if inAlbumList is not {} then
add inAlbumList to inAlbum
end if
if notinAlbumList is not {} then
add notinAlbumList to notInAlbum
end if
--add skippedPhotos to skippedAlbum
return "done"
end tell
This script is based on an draft published in this discussion by DanteToTheK : https://discussions.apple.com/thread/251399100?page=1