Script: Find all Photos for "On This Day" - an AppleScript
This user tip has been reformatted and moved here: Script: On this Day - Find all Photos, June 7, 2020
-- ignore --- old, deprecated version
This user tip has been migrated to: Script: Find all Photos for "On This Day"… - Apple Community, Feb 21,2019
The old code does no longer work
See this discussion "On This Day" Feature for mac Photos, does it exist? started by Solamanzi.
How to find all photos taken on a certain date through all years, for example, all photos taken on any of your birthdays or on any New Year's Eve.
It would be a bit cumbersome to define a smart album based on the date rule, because we would have to list all years separately.
Try this script: But try it on a test library, I have not done much testing: The current version will find all photos taken on the same month and day as the current date. Uncomment and modify the second and the third line to set the day and the month of the date to a fixed different date.
-- 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
set thisdate to the (current date) as date-- create a date object-- set the month of thisdate to 12 -- uncomment and change this to the month you want, for example 12-- set the day of thisdate to 25 -- uncomment and change this to the day you want, for example "25"
set thisday to the day of (thisdate as date)set thismonth to the month of (thisdate as date)
set thisDayAlbum to "On " & thismonth & " " & thisday as string
tell application "Photos" try
if existscontainerthisDayAlbum then delete the containerthisDayAlbum --- delete an existing previous album to be able to start with an empty album delay 2 -- wait for the album to be deleted 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 {} -- nothing found yet set onthisdaySkipped to {} -- nothing skipped yet
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 -- skipped, because the date could not be read end try end repeatend 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