08. Quick Look 的フォルダブラウズ ― 2013-04-26
Quick Lookはファイルを手早くプレビューできて便利ですが、よくある画像ブラウザのような「フォルダを選択しているとその内容をブラウズできる」仕様ではありません。
残念ながらAppleScriptではQuick Lookは扱えませんが、そのデバッグ環境であるqlmanageならシェルスクリプトで可能。
という実験で組んだスクリプトなので、フォルダ1個かQuick Lookのようにファイル(複数可)を選択しながら実行してみてください。
tell application "Finder"
try
set tgtkind to kind of (selection as alias)
if tgtkind = "Folder" then
set theFolder to selection as alias
set these_items to (every item of theFolder) as alias list
set these_paths to ""
repeat with theAlias in these_items
set these_paths to these_paths & space & (the quoted form of the POSIX path of theAlias)
end repeat
else
set these_paths to (the quoted form of the POSIX path of (selection as alias))
end if
on error
set these_items to selection as alias list
set these_paths to ""
repeat with theAlias in these_items
set these_paths to these_paths & space & (the quoted form of the POSIX path of theAlias)
end repeat
end try
end tell
do shell script "qlmanage -p " & these_paths & " >& /dev/null"
結果は、上の画像のようなデバッグウィンドウで中のファイルをブラウズできます。
デバッグ環境なので一覧ウィンドウに切り替えると操作がまるで利かず終了するしかありませんが、Finder windowを閉じてもデバッグウィンドウは残るのが利点?でしょうか。
スクリプトとしては、error処理にてselectionがkindを持たないリスト、つまり複数項目選択の場合を担当しているのが面白いかと。
errorを活用できるケース、確かにあるんですね。
残念ながらAppleScriptではQuick Lookは扱えませんが、そのデバッグ環境であるqlmanageならシェルスクリプトで可能。
という実験で組んだスクリプトなので、フォルダ1個かQuick Lookのようにファイル(複数可)を選択しながら実行してみてください。
tell application "Finder"
try
set tgtkind to kind of (selection as alias)
if tgtkind = "Folder" then
set theFolder to selection as alias
set these_items to (every item of theFolder) as alias list
set these_paths to ""
repeat with theAlias in these_items
set these_paths to these_paths & space & (the quoted form of the POSIX path of theAlias)
end repeat
else
set these_paths to (the quoted form of the POSIX path of (selection as alias))
end if
on error
set these_items to selection as alias list
set these_paths to ""
repeat with theAlias in these_items
set these_paths to these_paths & space & (the quoted form of the POSIX path of theAlias)
end repeat
end try
end tell
do shell script "qlmanage -p " & these_paths & " >& /dev/null"
結果は、上の画像のようなデバッグウィンドウで中のファイルをブラウズできます。
デバッグ環境なので一覧ウィンドウに切り替えると操作がまるで利かず終了するしかありませんが、Finder windowを閉じてもデバッグウィンドウは残るのが利点?でしょうか。
スクリプトとしては、error処理にてselectionがkindを持たないリスト、つまり複数項目選択の場合を担当しているのが面白いかと。
errorを活用できるケース、確かにあるんですね。
コメント
トラックバック
このエントリのトラックバックURL: http://darzilin.asablo.jp/blog/2013/04/26/6790498/tb
※なお、送られたトラックバックはブログの管理者が確認するまで公開されません。
コメントをどうぞ
※メールアドレスとURLの入力は必須ではありません。 入力されたメールアドレスは記事に反映されず、ブログの管理者のみが参照できます。
※なお、送られたコメントはブログの管理者が確認するまで公開されません。