Script: How to find photos without any keywords

by: 
Last modified: Jul 27, 2018 1:05 AM
7 7943 Last modified Jul 27, 2018 1:05 AM

Photos (version 1.0 to 3.0) has no option to search for photos that have not yet have any keywords assigned, like we could in Aperture or iPhoto. There is no search rule "Keyword is none" for the smart albums.

The Apple Script below can be used to look at selected photos in Photos and to add all photos to an album, that do not have any keywords.


See OT's post below for a download link.



(* Find All Photos Without Keywords © Léonie

--------------------------------


This script will scan the photos passed to it for keywords and add all photos without keywords to a standard album called missingKeywordsAlbum.

You can change the default name by adding a different album name in this line of the script: setmissingalbumnameto "missingKeywordsAlbum"


To use this script, select a some photos in Photos to check for missing keyword.

Then press the "Run" button.



The photos can be passed to the script in two ways:

1. Either select photos while viewing the "All Photos" album; this works better than Moments or smart albums

2. Or collect the Photos in a top level defined album with a fixed name. This is safer when your Photos Library is an iCloud Photo Library.


If you want to select the photos without collecting them in an album, set the variable "ReadFromAlbum" to false

If you want to pass the photos in a toplevel album, set ReadFromAlbum to true and change the variable "theAlbumName" to the name of the album you are using.


*)


set ReadFromAlbum to false


-- set this to true, if you want to pass the photos in a toplevel album

set theAlbumName to "PhotoDropBox" -- change this to the name of the album you will use



set imageSel to {}

set saved_delimiter to AppleScript'stext item delimiters--save the delimiter

set missingalbumname to "missingKeywordsAlbum"


tell application "Photos"


activate

if (ReadFromAlbum) then -- the photos will be passed in a toplevel album named "PhotoDropBox"


try


if existscontainertheAlbumName then


set thePhotosBuffer to containertheAlbumName

set imageSel to every media item of thePhotosBuffer

else

error "Album " & theAlbumName & "does not exist"

end if


on error errTexttwonumbererrNumtwo

display dialog "Cannot open album: " & errNumtwo & return & errTexttwo

end try


else -- process the selected photos from the All Photos album

try

set imageSel to (get selection)

on error errTexttwonumbererrNumtwo

display dialog "Cannot get the selection: " & errNumtwo & return & errTexttwo

end try


end if



-- check, if the album or the selected photos do contain images

if imageSel is {} then

error "Please select some images."

else -- create an album for the photos without keywords

try


if existscontainermissingalbumname then


set kwa to containermissingalbumname

else

set kwa to (makenewalbumnamedmissingalbumname)


end if


on error errTexttwonumbererrNumtwo

display dialog "Cannot open album missingKeywordsAlbum: " & errNumtwo & return & errTexttwo

end try


repeat with im in imageSel


try


tell im


--set the text item delimiter

set AppleScript'stext item delimiters to {", "} --use a comma and space as the delimiter


-- retrieve the keywords


set kws to its keywords as string

if (not (exists kws) or (kws is "missing value")) then

add {im} to kwa

end if


end tell

on error errText number errNum

display dialog "Error: " & errNum & return & errText & "Trying again"

try


delay 2 -- wait and try again

tell im


--set the text item delimiter

set AppleScript'stext item delimiters to {", "} --use a comma and space as the delimiter


-- retrieve the keywords


set kws to its keywords as string

if (not (exists kws) or (kws is "missing value")) then

add {im} to kwa

end if


end tell

on error errTexttwonumbererrNumtwo

display dialog "Skipping image due to repeated error: " & errNumtwo & return & errTexttwo

end try

end try

end repeat

end if

end tell

-- display dialog "Done"

set AppleScript'stext item delimiters to saved_delimiter--restore the delimiter


return "Done"

Comments

Jan 26, 2017 1:25 PM

Hi léonie,


It looks like the link in the User Tip to Dropbox is using a soon-to-be-deprecated URL format.

https://www.dropbox.com/help/16


You can create a "Shared Link" to work around this issue: https://www.dropbox.com/help/167


Of course, Old Toad's link should still work, but if you wanted to have a copy that you host yourself, then the link in the Tip should probably be updated before March of this year.

Jan 26, 2017 1:25 PM

Jan 28, 2017 12:01 AM

Thank you, stevejobsfan, good catch! I am not sure where I want to host scripts in the near future at all. That is why I am glad OT is providing a home for the scripts. A pity, that Apple does not have a website where we can put the scripts and other tools. I just cancelled my personal website subscription, because I stopped updating my webpages after the demise of iWeb.

Jan 28, 2017 12:01 AM

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