Currently Being Moderated

Script: Find all Photos for "On This Day" - an AppleScript

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 exists container thisDayAlbum then

    delete the container thisDayAlbum --- 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

  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 {} -- 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 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  -- skipped, because the date could not be read

  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

Replies

Delete User Tip

Are you sure you want to delete this user tip?