Using JavaScript to Find Photos Without Keywords

There is no way in Photos to get a list of all of the photos that have no keyword tags applied to them. But with a little JavaScript in Automator you can add this command to Photos and use it with all photos or any selection of photos.



Here is the text of the script:

function run(input, parameters) { var Photos = Application("Photos"); Photos.includeStandardAdditions = true var noKeywordAlbum = Photos.make({new:"album",named:"No Keywords"}); var selectedPhotos = Photos.selection(); for (var photo of selectedPhotos) { var keywords = photo.keywords(); if (keywords == null) { Photos.add([photo],{to:noKeywordAlbum}); } } }

Comments: 11 Responses to “Using JavaScript to Find Photos Without Keywords”

    David
    8 years ago

    Thanks Gary, I found this useful. Do you think something similar could work to find photos with "unnamed" \ "click to name" faces?

    8 years ago

    David: You don't really need this for faces, as the functionality inside Photos should work for that. But you can look in the Script Editor library window to see what other properties are available for the Photos app.

    STL
    8 years ago

    Outstanding post Gary. I'll be using these ideas. Thanks for a great blog with very useful information.

    nick
    8 years ago

    thank you, I'm always amazed how many hidden gems are within the Mac OS

    Dave
    8 years ago

    I wondered if you might record these commands in a simple cut and paste form for those of us not into Javascript ? Your selected words seem most adequate

    8 years ago

    Dave: I put them up under the video above.

    Ron
    8 years ago

    Gary, thank you. My library is arranged by "Title," but sometimes snaps taken on other devices enter All Photos w/o title and I don't notice until they're buried. Could I use this process/service by following your instructions but substituting "Title" for "Keyword"?

    Ron
    8 years ago

    Gary, I re-watched the video and had the idea that I should check out creating a smart album more fully, and I see that there IS an option right there for creating an album "Title" and "is empty." So, your video helped me answer my own question! Thank you!

    Bob
    8 years ago

    I have a lot of photos whose file name should be the title. I am trying to write a Javascript but am having difficulty with assigning the title to a variable. If the Title is null, set the Title to the filename.

    8 years ago

    Bob: Structures like "the Title" is AppleScript. Look in the Script Editor library to find JavaScript functions, but make sure you switch to JavaScript from AppleScript.
    For reading the title it is actually .name() and for setting it it is .name. You can get the file name with .filename(). You may want to check for both null and "" (empty string).

    Bob
    8 years ago

    Thanks,
    I done did it. Grin.
    I post links to many of your posts to our club's web pages.
    Thanks again.

Comments Closed.