2011年9月18日日曜日

[AppleScript] Finderで複数選択している項目を1つずつzipで圧縮

1つずつってのがミソです。

複数選択している状態で圧縮すると、デフォルトではまとめて圧縮されてしまいます。
しかしときには1つずつ圧縮したいケースもあるでしょう。(というか直面した)
コードは相変わらず9割コピペ。僕の仕事はGrowlを設定しただけ。
dittoが初参加です、ちょっと調べるとこれ便利ですね。これからお世話になりそう。
ditto(1) Mac OS X Manual Page

あと、今回のような時間がかかるときはGrowl入れる意味があって嬉しいです。
いつも自己満なんで。。。
しかし、ファイル操作のときはshell大活躍すぎてAppleScriptで書く意味がががが・・・
AppleScriptは当然として、shellも知っとかないとですねぇ。覚えることが多いっす。

set i to 0
tell application "Finder"
set fol_Path to (target of window 1) as alias
repeat with select_item in (selection as list)
set file_path to select_item as alias
set fil_name to name of file_path as text
set source to quoted form of POSIX path of (file_path as text)
set dest to quoted form of POSIX path of (fol_Path & fil_name & ".zip" as text)
do shell script "ditto -ck " & source & " " & dest
delay 1
set i to i + 1
end repeat
end tell
set grrDescription to i & "files" as text
my growlRegister()
growlNotify("End Run Zip", grrDescription)


using terms from application "GrowlHelperApp"
on growlRegister()
tell application "GrowlHelperApp"
register as application "選択項目をzipで圧縮" all notifications {"Notification"} default notifications {"Notification"} icon of application "Finder.app"
end tell
end growlRegister
on growlNotify(grrTitle, grrDescription)
tell application "GrowlHelperApp"
notify with name "Notification" title grrTitle description grrDescription application name "選択項目をzipで圧縮"
end tell
end growlNotify
end using terms from

0 件のコメント:

コメントを投稿