Aperture スレに触発されて前に書いて放置しといたスクリプトの高速化にトライしてみました。
ハッシュ大好きっ娘なのでそれに近いものがないかなー、と調べたら AppleScript ではレコードというものがハッシュ相当らしい。んだけど、 list で俺がやりたいことはできたので
- プロジェクトの一覧を取得したときに既存プロジェクトの名前を list に突っ込む(初回のみ)
- 写真を読むごとに list と比較してマッチしなければプロジェクトを作成
としてみました。高速化、というよりはプロジェクト/写真が多くなったときに遅くならない、という方向ですけどね。
で動かしてみたところ、確かに速くなったんだけど、一番条件が良くて 90 秒かかっていたものが 60 秒に縮んだぐらい? 期待よりも速くなってないというか写真一枚につき 1 秒以上かかってるようじゃなぁ。
ついでに選んだ写真の中に RAW が入ってると EXIF が取得できなくて止まっちゃうというバグもハッケソしてしまい、なんだかいやーな気分になってしまいました。せっかくだから公開するけどもっ!
tell application "Aperture"
set imageSel to (get selection)
set checkprojects to false
if imageSel is {} then
error "Please select an image."
else
set imgdate to ""
repeat with i from 1 to count of imageSel
tell (item i of imageSel)
if not (imgdate is equal to value of EXIF tag "ImageDate") then
set imgy to round (value of EXIF tag "CaptureYear") as number
set imgm to round (value of EXIF tag "CaptureMonthOfYear") as number
set imgd to round (value of EXIF tag "CaptureDayOfMonth") as number
if length of (imgm as string) = 1 then
set imgm to "0" & imgm
end if
if length of (imgd as string) = 1 then
set imgd to "0" & imgd
end if
set projname to (imgy as string) & "年" & (imgm as string) & "月" & (imgd as string) & "日"
set imgdate to value of EXIF tag "ImageDate"
end if
end tell
tell library 1
if checkprojects is false then
set projlist to {}
set projSel to get name of every project
repeat with existProj in projSel
set projlist to projlist & {contents of existProj}
end repeat
set checkprojects to true
end if
if projlist does not contain projname then
make new project with properties {name:projname}
set projlist to projlist & {projname}
end if
end tell
move item i of imageSel to project projname
end repeat
end if
end tell
コメントを残す