Tuesday, 10 August 2010

AppleScript 版 iPhoto 重複検出

AppleScript でサイズを見るのもやってみました。

激遲です。なので、一旦、duplicate1 ってアルバムに、検出する部分を集めて処理するのが良いらしい。3万件だと数時間かかるらしい。

  on fileSize(pt)
      tell application "System Events"
          return get size of file pt
      end tell
  end fileSize

  on inList(v, l)
      repeat with e in l
          if (v - (value of e) = 0) then
              return photo1 of e
          end if
      end repeat
      return -1
  end inList

  tell application "iPhoto"
      set sizeList to {}
      set duplist to {}
      set i to 1
      set al to some album whose name is "duplicate1"
      set c to count of photo of al
      set dup to some album whose name is "duplicate"
      repeat while i < c
          set p to photo i of al
          set s to my fileSize(image path of p)
          set d to my inList(s, sizeList)
          if d > 0 then
              add p to dup
              add photo d of al to dup
              say (i as string) & " is add"
              copy i to end of duplist
              copy {value:s, photo1:i} to end of sizeList
          end if
          set i to i + 1
      end repeat
  end tell

my とかが微妙にダサイ :-p 構造体も使えるのね。結構、便利。

Post a Comment