GameSprit

自転車やMac・AppleScript、映画・小説やドラマのレビュー、備忘メモ・クイズなどを置いています。

フォルダアクションを使ってみる - アイテムが追加されたとき-2

2006-11-05 18:05:21 | フォルダアクション
GameSprit フォルダアクションを使ってみる - アイテムが追加されたとき-1 の続きです。

ここでは追加されたアイテムに関する情報を取得します。

GameSprit フォルダアクションを使ってみる - アイテムが追加されたとき-1 を参考に、フォルダアクションを設定したフォルダを右クリック(1ボタンマウスでは control + クリック)して、「フォルダアクションを編集」します。


追加されたアイテム数を表示するスクリプトです。
アイテムをフォルダに追加すると、「~アイテムが <フォルダ名> に追加されました」と表示します。
count を使ってadded_itemsのリストの要素数を数えています。

on adding folder items to this_folder after receiving added_items

tell application "Finder"
set this_name to the name of this_folder
end tell

display dialog ((the count of added_items) as string) & "アイテムが" & this_name & "に追加されました"

end adding folder items to

-- Mac OS X 10.4.8 on Intel mac mini



フォルダアクションを設定した sendF というフォルダに、 some.txt と some のコピー.txt という2つのアイテムを追加してみます。






「2アイテムがsendFに追加されました」と表示されます。追加したアイテム数とフォルダ名が確認できました。







次に、追加されたアイテム名を取得してみます。
追加されるアイテムが複数になり得ることに注意します。
上記のスクリプトに改良を加え、追加されたすべてのアイテム名をダイアログの()内に表示します。
repeat with 変数 in added_items を使い、追加された全アイテムを処理します。

on adding folder items to this_folder after receiving added_items
tell application "Finder"
set this_name to the name of this_folder
end tell
set nr_addedItems to the count of added_items

try
set allItem to ""
repeat with aItem in added_items
tell application "Finder"
set aItem to the name of aItem
end tell
set allItem to allItem & " " & aItem as string
end repeat
set allItem to "(" & allItem & ")"
end try

display dialog (nr_addedItems as string) & "アイテムが" & this_name & "に追加されました" & return & allItem
end adding folder items to

-- Mac OS X 10.4.8 on Intel mac mini



フォルダアクションを設定した sendF というフォルダに、 some.txt と some のコピー.txt という2つのアイテムを追加してみます。






追加されたすべてのアイテム名がダイアログの()内に表示されました。






キーワード:フォルダアクションアイテム追加


最新の画像もっと見る

post a comment

ブログ作成者から承認されるまでコメントは反映されません。