I would simply ctrl-click the album in Photos sidebar and select "Delete Album" from the pop-up menu before you run the script. It will delete the album, but keep your photos in the library.
If you want to start with an empty album and include this deletion into the script, do it this way:
If the album exists, delete it, then recreate it unconditionally. This way the script will always start with an empty album.
if existscontainerthisDayAlbum then
delete the containerthisDayAlbum
end if
makealbumnamedthisDayAlbum
The script will now look like this:
------------------------------------------------------------
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 "1"
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
end if
makealbumnamedthisDayAlbum
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
If you are seeing an alert "Apple event timed out", you may not have responded to the dialog panel. This can happen, if the panel is hidden behind other windows.