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"
  set imageSel to (get selection)
  if imageSel is {} then
    error "Please select some images."
    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

One reply on “MacOS Photos and AppleScript”

Das Script hat mir wirklich eine ganze Menge Arbeit erspart! (hatte über 4000 Bilder mit fehlerhaftem Erstellungsdatum)
Vielen Dank!!


Leave a Reply

Your email address will not be published. Required fields are marked *

This site uses Akismet to reduce spam. Learn how your comment data is processed.