Advertisement
alexgorbachev

Add dates to Aperture project names

Dec 15th, 2012
178
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. (*
  2. Rename Aperture Projects
  3.  
  4. This script loops through each project located within the "Events" folder in Aperture. For each project
  5. found, all photos within are examined, and the oldest photo's date is used to rename the project to the
  6. format "YYYY-MM-DD | Previous_Project_Name". This script can be used each time you import, and then
  7. the projects can be moved to other folders. Make sure you have just one "Events" folder in your library
  8. (even in the Trash folder).
  9.  
  10. © 2011,2012 Tim Doyle, timdoyletx at gmail dot com
  11. -- modified by Alex Gorbachev 15-Dec-2012 (folder name dialog + last date addition)
  12. *)
  13.  
  14. on formatData(_theDate)
  15.     set _tday to day of _theDate as number
  16.     if _tday < 10 then
  17.         set _day to "0" & (_tday as string)
  18.     else
  19.         set _day to _tday as string
  20.     end if
  21.    
  22.     set _tmonth to month of _theDate as number
  23.     if _tmonth < 10 then
  24.         set _month to "0" & (_tmonth as string)
  25.     else
  26.         set _month to _tmonth as string
  27.     end if
  28.    
  29.     set _year to year of _theDate as string
  30.    
  31.     return _year & "-" & _month & "-" & _day
  32. end formatData
  33.  
  34. --set rootFolder to display dialog "Enter folder name" default answer "Events"
  35. tell application "Aperture"
  36.     activate
  37.     set rootFolder to "Events"
  38.     display dialog "Enter folder name" default answer rootFolder
  39.     set rootFolder to text returned of result
  40.    
  41.     tell library 1
  42.         set _projects to every project in folder rootFolder
  43.         repeat with p from 1 to count of _projects
  44.            
  45.             tell item p of _projects
  46.                 set projectName to name
  47.             end tell
  48.             --display dialog "PN=" & projectName
  49.            
  50.             tell current application
  51.                 if (offset of "|" in projectName) > 0 then
  52.                     set eventName to text ((offset of "|" in projectName) + 2) thru (length of projectName) of projectName
  53.                 else
  54.                     set eventName to projectName
  55.                 end if
  56.             end tell
  57.             --display dialog "EN=" & eventName
  58.            
  59.             set _versions to every image version in item p of _projects
  60.             set minImageDate to ""
  61.             set maxImageDate to ""
  62.             repeat with v from 1 to count of _versions
  63.                 tell item v of _versions
  64.                     set thisImageDate to value of EXIF tag "ImageDate"
  65.                     set thisImageDate to thisImageDate - (time of thisImageDate)
  66.                 end tell
  67.                 if (minImageDate = "") then
  68.                     set minImageDate to thisImageDate
  69.                 else
  70.                     if (thisImageDate < minImageDate) then
  71.                         set minImageDate to thisImageDate
  72.                     end if
  73.                 end if
  74.                 if (maxImageDate = "") then
  75.                     set maxImageDate to thisImageDate
  76.                 else
  77.                     if (thisImageDate > maxImageDate) then
  78.                         set maxImageDate to thisImageDate
  79.                     end if
  80.                 end if
  81.             end repeat
  82.            
  83.             if minImageDate = maxImageDate then
  84.                 set _name to formatData(minImageDate) of me & " | " & eventName
  85.             else
  86.                 set _name to formatData(minImageDate) of me & " | " & eventName & " <" & formatData(maxImageDate) of me
  87.             end if
  88.            
  89.             --display dialog "Would have renamed " & projectName & " to " & _name
  90.             tell item p of _projects
  91.                 set name to _name
  92.             end tell
  93.            
  94.         end repeat
  95.     end tell
  96. end tell
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement