Photos sorted by date
I am trying to get my photos to sort by date. I asked AI to create a script for me but Apple says there is an error "Expected “,” but found identifier." Can anyone fix? Chatgpt can't fix it and I don't know anything about writing scripts
tell application "Photos"
set selectedAlbum to (get selection)
if selectedAlbum is {} then
set allImages to media items of every album
else
set allImages to media items of every album whose name is name of item 1 of selectedAlbum
end if
set sortedImages to (sort allImages by date)
repeat with thisImage in sortedImages
set creationDate to (get (media item date thisImage))
set creationYear to year of creationDate as text
set creationMonth to month of creationDate as integer
set creationDay to day of creationDate as integer
set yearAlbum to (get album named creationYear)
if yearAlbum is missing value then
set yearAlbum to make new album with properties {name:creationYear}
end if
set monthAlbum to (get album named ((text -2 thru -1 of ("0" & (creationMonth as text))) & " - " & (month of (creationDate as date) as text)))
if monthAlbum is missing value then
set monthAlbum to make new album with properties {name:((text -2 thru -1 of ("0" & (creationMonth as text))) & " - " & (month of (creationDate as date) as text)), parent:yearAlbum}
end if
set dayAlbum to (get album named (text -2 thru -1 of ("0" & (creationDay as text))))
if dayAlbum is missing value then
set dayAlbum to make new album with properties {name:(text -2 thru -1 of ("0" & (creationDay as text))), parent:monthAlbum}
end if
add thisImage to dayAlbum
end repeat
end tell
MacBook Pro (M2, 2022)
