Set creation and modification date

This is to correct file times on photos that were imported from cameras with bad date settings or when they have been transferred to-and-fro and picked up the wrong data some where or after re-encoding high bit rate video to save a few GBs.

(*
http://strawhousepig.net/

This AppleScript utilizes Apple's command line developer tools command 'setfile' to set the modification date.

https://developer.apple.com/download/more/

I believe an Apple Developer account is required for that, but I am not sure.

*)

set oldfile to choose file
tell application "Finder" to set filename to displayed name of oldfile
set newyear to text returned of (display dialog "4 digit year" with title filename default answer (do shell script "date '+%Y'"))
set newmonth to text returned of (display dialog "2 digit month" with title filename default answer (do shell script "date '+%m'"))
set newdate to text returned of (display dialog "2 digit date" with title filename default answer (do shell script "date '+%d'"))
set newtime to text returned of (display dialog "24 hour time" with title filename default answer "0000")

try
  do shell script "touch -t " & newyear & newmonth & newdate & newtime & space & quoted form of POSIX path of oldfile
on error theErr
  display dialog "The 'touch' command said:" & theErr
end try
try
  do shell script "setfile -d '" & newmonth & "/" & newdate & "/" & newyear & " " & characters 1 through 2 of newtime & ":" & characters 3 through 4 of newtime & "' " & quoted form of POSIX path of oldfile
on error theErr
  display dialog "The 'setfile' command said:" & theErr
end try

Leave a Reply

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