環境: Mac OS X 10.4.9 (PPC)
AppleScript で項目がフォルダかどうかを判別する方法はいくつもあると思いますが、言語環境に依存しないのをひとつ。
Finder の選択項目を言語環境に関わらず判別したかったら、kind of ... ではなく class of ... という書き方をしますよね。
tell application "Finder"
set theItem to (item 1 of (selection as list))
if (class of theItem) is folder then
display dialog "folder"
end if
end tell
ところがドロップレットの場合、値が alias のリストで渡されるようで、class of ... の結果は 常に alias となってしまい、フォルダかどうかの判別ができません。
on open dropItems
tell application "Finder"
set theItem to (item 1 of dropItems)
if (class of theItem) is folder then
display dialog "folder"
else if (class of theItem) is alias then
display dialog "alias"
end if
end tell
end open
そんなときはこう書くと良いようです。
on open dropItems
set theItem to (item 1 of dropItems)
tell application "Finder"
if class of ((properties of theItem) as record) is folder then
display dialog "folder"
end if
end tell
end open
as record がミソ。
項目の properties をレコードと明示して、そこから class というラベルの値を取り出している、という考え方でいいんでしょうか。
理屈はよくわかりませんが、とりあえず目的にかなうのでいいっぽい。
追記: コメント欄も見てちょ。
Finderを介在させると、その他の処理に使えない形式のデータを扱わなくてはいけないため、スクリプトが複雑になりがちで、予想外のバグが出る原因にもなります。
で、本来は
folder of (info for theItem)
という真偽属性を用いるべきです。
openハンドラ上でFinderに依存せずフォルダを判定するならば、
on open dropItems
set theItem to (item 1 of dropItems)
tell application "Finder"
if folder of (info for theItem) then
display dialog "folder"
end if
end tell
end open
とするのが良いように思います。
folder of (info for ...) の場合、package folder でも true になってしまうという落とし穴があるです。
RTFD 形式のファイルや、OmniOutliner の添付書類付きファイルなどもパッケージですから、info for を使うならそのへんを考慮してこんな風に書いた方がいいんじゃないかなと。
if (folder of (info for theItem)) and not (package folder of (info for theItem)) then
...
end if
といってますが、実はご指摘があるまで info for という書き方があることを完全に忘れていました。
ありがとうございました。