Datei-Datum von Aufnahme-Datum

Man hat 19'000 Bilder, die kopiert werden oder im Aperture waren und dort exportiert wurden. Nun bekommen sie das Datum des Exportes, also heute. Fort ist das eigentliche Datum und so kann man sie auch schlecht sortieren.

Nun könnte man mit XX Programm die Datei nach dem Aufnahme-Datum (und Urzeit umbenennen), also
PIC0001.jpg wird dann 2012-11-02-12-34.jpg
Aber das ist irgendwie nicht toll, man sollte ja auch den eigentliche Dateinamen wieder erkennen können.

  • Exif Datum lässt sich einfach mit Aperture 2.0 ändern: Metadaten -> Datum und Uhrzeit anpasssen. Dazu braucht es gar kein App mehr.
  • Exiftool: Das ist aber ein Terminal Programm - wohl bekomms... (Näheres dazu hier)
  • A better finder Attributes ist vor allem ein Programm mit dem man Exif Daten manipulieren kann. Aber eben nicht das File Datum ändern.

Umgekehrt kann das Programm Amok Exif Sorter aus zig Tausend Dateien aus den Exif Informationen die Bilder selber in Ordner einordnen. Recht genial, aber nicht so trivial die Anwendung.

Erstaunlicherweise konnte ich dazu lange nichts finden. Und dann wurde ich auf ein kleines, aber geniales Apple Script aufmerksam:

Ein "Skeeve" hat es in Macworld gepostet: Es funktioniert einfach genial. Super, kann man da nur sagen. Einfach Apple Script aufrufen, diesen Text einfügen und Ausführen klicken und schon kann man die Dateien auswählen. Danach werden alle Daten umbenannt. Hier auch noch einen Text dazu.

------------------------------------------------------------------------
-- 
-- EXIF-touch V0.3 (C) exif-touch.info.skeeve@xoxy.net
-- 
-- this program was first published on
-- http://www.fischer-bayern.de/
-- 
-- You may use it without warranty under the terms of the GPL
-- 
-- You can drop any combination of JPEG files and folders on this script
-- or simply start it to select JPEG files.
-- The file's creation date will then be change to the image's creation
-- date, provided there is one in the EXIF tags.
-- 
------------------------------------------------------------------------

global ignoreMissingValue, ignoreWrongDate

-- if run, you may choose jpeg files
on run
   set imgAlias to choose file of type {"public.jpeg"} with multiple selections allowed without invisibles
   tell application "Image Events" to activate
   set ignoreMissingValue to false
   set ignoreWrongDate to false
   try -- when canceled err# -128 is returned
      EXIF_touch_list(imgAlias)
   on error errmsg number errn
      if errn /= -128 then
         display_error(errmsg, errn, false)
      end if
   end try
   tell application "Image Events" to quit
end run

-- you may drop any file or folder or combination thereof
-- folders are handled recursively
-- files with type identifier "public.jpeg" are handled
-- all other files are simply ignored
on open itemList
   tell application "Image Events" to activate
   set ignoreMissingValue to false
   set ignoreWrongDate to false
   try -- when canceled err# -128 is returned
      EXIF_touch_list(itemList)
   on error errmsg number errn
      if errn /= -128 then
         display_error(errmsg, errn, false)
      end if
   end try
   tell application "Image Events" to quit
end open

-- you may append this script to any folder
-- it will work on all added items
-- folders are handled recursively
-- files with type identifier "public.jpeg" are handled
-- all other files are simply ignored
on adding folder items to this_folder after receiving these_items
   tell application "Image Events" to activate
   set ignoreMissingValue to false
   set ignoreWrongDate to false
   try -- when canceled err# -128 is returned
      EXIF_touch_list(these_items)
   on error errmsg number errn
      if errn /= -128 then
         display_error(errmsg, errn, false)
      end if
   end try
   tell application "Image Events" to quit
end adding folder items to

-- recursive handler to call EXIF_touch for image files
on EXIF_touch_list(itemList)
   repeat with singleItem in itemList
      set information to info for singleItem as alias
      if folder of information then
         tell application "Finder"
            set x to (every file of singleItem)
            my EXIF_touch_list(x) -- all (image) files
            set x to (every folder of singleItem)
            my EXIF_touch_list(x) -- all folders
         end tell
      else if type identifier of information is "public.jpeg" then
         EXIF_touch(singleItem as alias) -- just one single (image) file
      end if
   end repeat
end EXIF_touch_list

-- does the touch
on EXIF_touch(imgAlias)
   tell application "Image Events"
      set img to open imgAlias
      set allDates to value of every metadata tag of img whose name is "creation"
      close img
   end tell
   
   -- I'm not sure whether or not we have several creation dates for the image
   -- so I pick the oldest
   set creationDate to min(allDates)
   if creationDate is missing value then
      if not ignoreMissingValue then
         display_error("The image" & return & "«" & (imgAlias as string) & "»" & return & "Has no EXIF tags or at least no creation date", "No EXIF data", true)
         set ignoreMissingValue to true
      end if
      return
   end if
   
   -- check the creation date of the file
   tell application "Finder" to set fileCreation to creation date of imgAlias
   set fileCreation to EXIF_format(fileCreation)
   
   -- check today's date
   set today to EXIF_format(current date)
   
   -- all dates are in EXIF format, which is YYYY:MM:DD hh:mm:ss
   -- so we can easily compare
   if creationDate <= fileCreation then
      -- a simple touch works if we set the modified and access time
      -- to a date prior to file creation
      touch(creationDate, imgAlias)
   else if creationDate <= today then
      -- if the image was created before today, but after file creation
      -- (strange things might happen!) we refresh the image to
      -- today's date by copying it
      touch(creationDate, refresh(imgAlias))
   else -- damn! Something is wrong!
      display_error("Your computer's date (" & today & ") is lower than the creation date (" & creationDate & ") of the image" & return & "«" & (imgAlias as string) & "»" & return & "Please try to fix this before you proceed.", "Wrong Date", true)
      set ignoreWrongDate to true
   end if
end EXIF_touch

-- make a cp (copy) of the file
-- this sets the file's creation date to the current date
on refresh(anAlias)
   set oldPath to POSIX path of anAlias
   if backup(anAlias) then
      do shell script "cp " & quoted form of POSIX path of anAlias & " " & quoted form of oldPath & " && rm " & quoted form of POSIX path of anAlias
      return (POSIX file oldPath) as alias
   end if
   return missing value
end refresh

-- renames the file
-- appends " bck" to the filename (or " bck-#") if it already exists
on backup(anAlias)
   tell application "Finder"
      set n to name of anAlias
      set e to name extension of anAlias
      if e is not "" then
         set n to text 1 thru (-2 - (length of e)) of n
         set e to "." & e
      end if
      set i to ""
      repeat
         try
            set name of anAlias to n & ".bck" & i & e
            exit repeat
         on error errmsg number errnr
            if errnr /= -48 then
               set errmsg to errmsg & return & return & "File: " & (anAlias as string)
               my display_error(errmsg, errnr, true)
               return false
            end if
            set i to i - 1
         end try
      end repeat
   end tell
   return true
end backup

-- newDate has to be in EXIF format
on touch(newDate, anAlias)
   if class of anAlias is not alias then return
   set x to words of newDate
   set x to ((items 1 thru -2 of x) as string) & "." & last item of x
   do shell script "touch -t " & x & " " & quoted form of POSIX path of anAlias
end touch

-- return the minimum of the list
on min(aList)
   try
      set a to first item of aList
   on error
      return missing value
   end try
   repeat with b in rest of aList
      if a > b then set a to b
   end repeat
   return a
end min

-- format a date to EXIF format
on EXIF_format(aDate)
   set {year:y, month:m, day:d, hours:hh, minutes:mm, seconds:ss} to aDate
   return (y & ¬
      ":" & (leftfill of (m as integer) by "00") & ¬
      ":" & (leftfill of d by "00") & ¬
      " " & (leftfill of hh by "00") & ¬
      ":" & (leftfill of mm by "00") & ¬
      ":" & (leftfill of ss by "00")) as string
end EXIF_format

-- leftfill of 4711 by "000000" => "004711"
to leftfill of aNumber by pattern
   set aNumber to aNumber as string
   set missing to (length of pattern) - (length of aNumber)
   if missing <= 0 then return aNumber
   return (text 1 thru missing of pattern) & aNumber
end leftfill

-- display the error
on display_error(errmsg, errnr, ignore)
   set btns to {"OK"}
   if ignore then
      set btns to {"Ignore", "OK"}
   end if
   set errTitle to "Error"
   if errnr is not missing value then
      set errTitle to errTitle & " (" & errnr & ")"
   end if
   display dialog errmsg with title errTitle buttons btns default button "OK" with icon stop
   if button returned of result is "OK" then error number -128
end display_error

Kommentare

Beliebte Posts aus diesem Blog

Interlinear Bibel

McAfee Deinstallieren