Fischer-Bayern.de
 FAQFAQ   SuchenSuchen   MitgliederlisteMitgliederliste   BenutzergruppenBenutzergruppen   RegistrierenRegistrieren 
 ProfilProfil   Einloggen, um private Nachrichten zu lesenEinloggen, um private Nachrichten zu lesen   LoginLogin 

EXIF-touch V0.3

 
Neues Thema eröffnen   Neue Antwort erstellen    Fischer-Bayern.de Foren-Übersicht -> AppleScript X
Vorheriges Thema anzeigen :: Nächstes Thema anzeigen  
Autor Nachricht
Skeeve
•---->
•---->


Anmeldedatum: 20.04.2006
Beiträge: 1061

BeitragVerfasst am: 03.01.2007 - 20:25    Titel: EXIF-touch V0.3 Antworten mit Zitat

Ausgehend von diesem Thread, habe ich mich mal ein bischen mehr in AppleScript geübt. Dieses Script ist nicht idiotensicher Wink aber, wie ich denke, ein guter Anfang und eine, wie ich hoffe, gute Diskussionsgrundlage.

Ich habe es in Englisch gehalten, weil ich
  1. das beruflich immer so mache(n muß)
  2. denke, daß es auch in anderen Ländern hilfreich sein kann.
  3. zu faul bin es in 2 Sprachversionen zu pflegen

Was mich am Meisten stört im Moment ist, daß noch eine vernünftige Fehlerbehandlung für schreibgeschützte Dateien/Ordner fehlt. Ich denke sogar, daß es in so einem Fall im backup Handler zu einer Endlosschleife kommen wird.

Update: s.u. für V0.3
_________________
"All problems are solved in slightly less than half an hour" (Chumbawamba, "Hey Hey We're The Junkies")


Zuletzt bearbeitet von Skeeve am 04.01.2007 - 00:33, insgesamt einmal bearbeitet
Nach oben
Benutzer-Profile anzeigen Private Nachricht senden
iScript
•---->
•---->


Anmeldedatum: 29.03.2001
Beiträge: 1114

BeitragVerfasst am: 03.01.2007 - 22:29    Titel: Antworten mit Zitat

hi, skeeve

hast dich ja mächtig ins zeug gelegt. und perl kommt nur 1mal vor Wink
kann man eigentlich auch alle metadata tags eines images auch in einem rutsch (incl. ihrer values!) auslesen. ich bekomme das irgendwie nicht hin. und sind das immer die gleichen, oder differieren diese zwischen unterschielichen bildformaten?

   set allMetas to metadata tags of img -- whose name is "creation"
liefert nur die metatags
   set allMetas to value of every metadata tag of img -- whose name is "creation"
liefert (logisch) nur die werte

ich meine so ähnlich wie bei info for ...
Nach oben
Benutzer-Profile anzeigen Private Nachricht senden E-Mail senden Website dieses Benutzers besuchen AIM-Name
Skeeve
•---->
•---->


Anmeldedatum: 20.04.2006
Beiträge: 1061

BeitragVerfasst am: 04.01.2007 - 00:11    Titel: Antworten mit Zitat

iScript hat Folgendes geschrieben:
hast dich ja mächtig ins zeug gelegt. und perl kommt nur 1mal vor

Und selbst das könnte ich sparen, wenn ich wüßte, daß AppleScript effektiver darin ist den text "2006:12:31 23:59:00" zu konvertieren in "200612312359.00" Im Prinzip sollte es das hier tun:
set x to words of "2006:12:31 23:59:00"
((items 1 thru -2 of x) as string) & "." & last item of x

Aber da ich an der Stelle nun schon mal in der shell bin. Andererseits... Ach! Warum nicht! (s.u.)

iScript hat Folgendes geschrieben:
kann man eigentlich auch alle metadata tags eines images auch in einem rutsch (incl. ihrer values!) auslesen. ich bekomme das irgendwie nicht hin. und sind das immer die gleichen, oder differieren diese zwischen unterschielichen bildformaten?

Ich habe keine Ahnung! Ich bin nur ein Dilettant, der hier rumexperimentiert. Und das hat mich zu diesem ERgebnis geführt:
set imgAlias to choose file of type {"public.jpeg"} without invisibles
tell application "Image Events"
   activate
   set img to open imgAlias
   set allMetas to every metadata tag of img
   set erjebnis to ""
   repeat with aMeta in allMetas
      set erjebnis to erjebnis & name of aMeta & ": " & value of aMeta & return
   end repeat
   close img
end tell
display dialog erjebnis
Also: Dein Erster Ansatz war im Prinzip richtig.

Hier aber nun V0.2 von EXIF-touch:
------------------------------------------------------------------------
--
-- EXIF-touch V0.2 (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

-- 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

_________________
"All problems are solved in slightly less than half an hour" (Chumbawamba, "Hey Hey We're The Junkies")
Nach oben
Benutzer-Profile anzeigen Private Nachricht senden
Skeeve
•---->
•---->


Anmeldedatum: 20.04.2006
Beiträge: 1061

BeitragVerfasst am: 04.01.2007 - 00:31    Titel: Antworten mit Zitat

V0.3, auch als Folder Action geeignet.
------------------------------------------------------------------------
--
-- 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

_________________
"All problems are solved in slightly less than half an hour" (Chumbawamba, "Hey Hey We're The Junkies")
Nach oben
Benutzer-Profile anzeigen Private Nachricht senden
Beiträge der letzten Zeit anzeigen:   
Neues Thema eröffnen   Neue Antwort erstellen    Fischer-Bayern.de Foren-Übersicht -> AppleScript X Alle Zeiten sind GMT + 2 Stunden
Seite 1 von 1

 
Gehe zu:  
Du kannst keine Beiträge in dieses Forum schreiben.
Du kannst auf Beiträge in diesem Forum nicht antworten.
Du kannst deine Beiträge in diesem Forum nicht bearbeiten.
Du kannst deine Beiträge in diesem Forum nicht löschen.
Du kannst an Umfragen in diesem Forum nicht mitmachen.


Powered by phpBB © 2001, 2002 phpBB Group
Deutsche Übersetzung von phpBB.de


AppleScript für absolute Starter