Categories
Allgemein MacOS Programmierung

MacOS Photos and AppleScript

Just about to move from Adobe Lightroom (CC) to native Apple Photo App/iCloud (but thats another story).

Unfortunately most of the old AVI videos got a wrong date during the import (not the file-creation date but the date of import). Not helpful. Fortunately Lightroom had set the date/time into the filename, so I should be able to set it from there.

In the end I spent my first night with with AppleScript – thats the outcome:

tell application "Photos"
  activate
  set imageSel to (get selection)
  if imageSel is {} then
    error "Please select some images."
  else
    repeat with im in imageSel
      tell im
        set imageFilename to filename of im as string
        set d to current date

        -- filename format: 20030316_160816_03498.avi
        set the year of d to text 1 thru 4 of imageFilename
        set the month of d to text 5 thru 6 of imageFilename
        set the day of d to text 7 thru 8 of imageFilename
        set the hours of d to text 10 thru 11 of imageFilename
        set the minutes of d to text 12 thru 13 of imageFilename
        set the seconds of d to text 14 thru 15 of imageFilename

        set the date of im to d
      end tell
    end repeat
  end if
end tell
return input