Script: How to search for photos from yearly recurring events
You can search in Photos for a month using the search field, but not for a particular, recurring day:
For some dates you can ask Siri to find the pictures.
"Show me Pictures of New Year's Eve"
For a more specific search you could write an Apple Script. The script below will ask for a day and month in the format dd:mm and collect all photos for this day of the year in an album, independent of the year.
After entering the day and month click the OK button, and then wait. It takes several minutes to search my library with 50000 photos.
To use this script, paste it into a Script Editor window and save it as a new script. Click the Run button. The search will take a long time for a large library.
The result will appear as a new album named for the day and month.
-- snip - snip -- snip ---copy from here
-- Find all photos taken on a certain day, for example the day of the current date.
-- The resulting photos will be added to a toplevel album named "On <day> <month>".
-- Author Léonie, March 8,2016, modified on November 20, 2018
set userCanceled to false
try
set dialogResult to display dialog ¬
"Enter the day and month in the format dd:mm" buttons {"Cancel", "OK"} ¬
default button "OK" cancel button ¬
"Cancel" giving up after 15 ¬
default answer "24:12"
on error number -128
set userCanceled to true
end try
if userCanceled then
-- statements to execute when user cancels
display dialog "User cancelled."
return "User cancelled."
else if gave up of dialogResult then
display dialog "User timed out."
return "timeout"
end if
-- parse the dd:mm string
set theresult to the text returned of dialogResult
set thisdate to the (current date) as date-- create a date object
set the month of thisdate to ((word 2 of theresult) as number)
set the day of thisdate to ((word 1 of theresult) as number)
set thisday to the day of (thisdate as date)
set thismonth to the month of (thisdate as date)
--return {thisday, thismonth}
set thisDayAlbum to "On " & thismonth & " " & thisday as string
tell application "Photos"
try
if existscontainerthisDayAlbum then
delete the containerthisDayAlbum
delay 2 -- second try after delay
end if
makealbumnamedthisDayAlbum-- create a new, empty album
on error errTexttwonumbererrNumtwo
display dialog "Cannot create album: " & thisDayAlbum & " " & errNumtwo & return & errTexttwo
return
end try
set onthisdayFound to {}
set onthisdaySkipped to {}
set allTheItems to every media item-- get a list of all photos and videos, may take a while
-- add all photos taken this day to the album
repeat with i from 1 to the count of allTheItems
-- check the dates of all photos and videos
set thisMediaItem to itemi of allTheItems
try
set date_i to the date of thisMediaItem
set day_i to the day of (date_i as date)
set month_i to the month of (date_i as date)
if ((day_i = thisday) and (month_i = thismonth)) then
set end of onthisdayFound to thisMediaItem
add {thisMediaItem} tocontainerthisDayAlbum
end if
on error errTexttwonumbererrNumtwo
set end of onthisdaySkipped to thisMediaItem
end try
end repeat
end tell
set theresultmessage to "Found " & (the count of onthisdayFound) & " items and added them to the album " & thisDayAlbum & ".
Skipped " & (the count of onthisdaySkipped) & " items without date"
display dialogtheresultmessage
-- end of script
The script is really slow, but you can open the album it is filling with photos and watch the progress.
This user tip was generated from the following discussion: Complex Photo Search?