Apple’s old iPhotos application for Mac OS X had a convenient feature that allowed me to flag 🏴 photos for subsequent actions: comparing, editing, exporting, and preparing to share. The new Apple Photos application does not support flagging. All the flags in my photo library were turned into the “Flagged” keyword when I upgraded from iPhoto to Photos. The new Favorite ❤️ marking feature may do what I want. I should take some time to familiarize myself with its usage but until that time, I need a way to easily set and clear the “Flagged” keyword from individual and groups of photos.
Sure, I could bring up the info box for a photo and edit the keyword field to add or remove the “Flagged” keyword. That however is too many steps to repeat for more than a few photos. Scripting to the rescue.
I wrote a couple of AppleScript services that extend the flagging feature to Photos. It is not as convenient as clicking the flag icon in the corner of a photograph, but it is ready at hand from the Photos > Services menu.
The Scripts
This first script is called Flag and, true to its name, it adds the “Flagged” keyword to all currently selected photos in the Photos application window. The name is important, because that is how the command will appear in the Photos > Services menu.
-- Add "Flagged" keyword to selected Photos tell application "Photos" set selected to the selection if selected = {} then display alert "No photos selected to flag" giving up after 10 else repeat with photo in selected set tags to the keywords of photo if tags = missing value then set tags to {"Flagged"} else if tags does not contain "Flagged" then copy "Flagged" to the end of tags end if set the keywords of photo to tags end repeat display alert "Photos flagged" giving up after 10 end if end tell
The other script, appropriately named Unflag, removes the “Flagged” keyword from the currently selected photos.
-- Remove "Flagged" keyword from selected Photos tell application "Photos" set selected to the selection if selected = {} then display alert "No photos selected to unflag" giving up after 10 else repeat with photo in selected set tags to the keywords of photo if tags ≠ missing value and tags contains "Flagged" then set newtags to {} repeat with tag in tags if tag as string is not "Flagged" then set end of newtags to tag end if end repeat set the keywords of photo to newtags end if end repeat display alert "Photos unflagged" giving up after 10 end if end tell
Installation
These scripts are best used as Automator Workflow services installed in the ~/Library/Services folder.
Run Automator, and choose “Service” as the type of your new document.
Edit the name of the service at the top of the Automator title bar. Change its name to Flag.
Modify the type of information provided to the service at the top of the workflow pane as follows.
Drag a “Run AppleScript” action from the utilities library into the workflow pane then replace the (* Your script goes here *) comment with the Flag AppleScript code listed above.
Close the workflow editor window. Then quit Automator. Run Automator again and cancel out of any requests to open or create a document.
From the File > Open Recent menu, choose Flag. Automator will ask if you want to install the Flag service. Click the Install button.
Repeat these steps to create and install the Unflag service.
You now have two services that will appear in the Photos > Services menu: Flag and Unflag.
Using the Services
Fire up Photos, then select one or more photos.
Choose Photos > Services > Flag. A brief alert will pop up that says the photos have been flagged.
You can bring up the info dialog for one of the selected photos and you will see that the “Flagged” keyword has been added to the photo.
You can use the Photos > Services > Unflag menu command to unflag selected photos.
Now to see if Favorite ❤️ is good for anything.