Script: Find all Photos for "On This Day" - 2019 Version

by: 
Last modified: Jun 7, 2020 10:29 AM
2 1095 Last modified Jun 7, 2020 10:29 AM

This user tip has been reformatted and moved here: Script: On this Day - Find all Photos


-------------------------- Deprecated, do not use this version ---------------------------------

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.


-- copy from here into Script Editor. ✄-- ✄-- ✄-- ✄-- ✄-- ✄-- ✄-- ✄-- ✄-- ✄-- ✄--

-- 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 -- change this to the month you want, for example 12
--set the day of thisdate to 1 -- 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)
--return {thisday, thismonth}

set thisDayAlbum to "On " & thismonth & " " & thisday as string

tell application "Photos"
	try
		
		if exists container thisDayAlbum then
			delete the container thisDayAlbum
			delay 2 -- second try after delay
		end if
		make album named thisDayAlbum -- create a new, empty album
	on error errTexttwo number errNumtwo
		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 item i 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} to container thisDayAlbum
			end if
		on error errTexttwo number errNumtwo
			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 dialog theresultmessage



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