Created
January 16, 2010 23:48
-
-
Save cimm/279094 to your computer and use it in GitHub Desktop.
AppleScript that gets the selected photos in iPhoto, extracts the iPhoto date and adds it in the photo EXIF data.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
property script_name : "RepairiPhotoDates" | |
property script_version : "0.2" | |
property script_description : "Gets the selected photos in iPhoto, extracts the iPhoto date and adds it in the photo EXIF data." | |
property script_copyright : "Creative Commons Attribution 3.0 License" | |
property script_author : "Simon Schoeters" | |
property script_website : "http://www.suffix.be/" | |
-- Open iPhoto, select the photos you need and run the script, it will replace the date in the EXIF headers with the data iPhoto shows. You'll need ExifTool by Phil Harvey (www.sno.phy.queensu.ca/~phil/exiftool/) installed to make this work. | |
tell application "iPhoto" | |
activate | |
try | |
copy (my selected_images()) to these_images | |
if these_images is false then error "Please select some images in iPhoto." | |
set this_paths to {} | |
repeat with i from 1 to the count of these_images | |
set this_image to item i of these_images | |
set this_path to the image path of this_image | |
set this_path to quoted form of this_path -- escape spaces | |
set {year:y, month:mo, day:d, hours:h, minutes:mi, seconds:s} to the date of this_image | |
if (mo as integer < 10) then set mo to "0" & (mo as integer) | |
if (d as integer < 10) then set d to "0" & (d as integer) | |
if (h as integer < 10) then set h to "0" & (h as integer) | |
if (mi as integer < 10) then set mi to "0" & (mi as integer) | |
if (s as integer < 10) then set s to "0" & (s as integer) | |
set this_date to y & ":" & mo & ":" & d & " " & h & ":" & mi & ":" & s | |
do shell script "exiftool '-DateTimeOriginal=\"" & this_date & "\"' '-CreateDate=\"" & this_date & "\"' " & this_path | |
end repeat | |
on error error_message number error_number | |
if the error_number is not -128 then | |
display dialog error_message buttons {"OK"} default button 1 | |
end if | |
return "Cancelled" | |
end try | |
end tell | |
on selected_images() | |
tell application "iPhoto" | |
try | |
set these_items to the selection | |
if the class of item 1 of these_items is album then error | |
return these_items | |
on error | |
return false | |
end try | |
end tell | |
end selected_images |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment