1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30
http://wakabamac.blog95.fc2.com/blog-entry-555.html

Quicksilver : ランチャ+システムの一部のような総合ユーティリティ
前の記事『Quicksilver/ AppleScript で Action を作る(2)』に続き、AppleScript を使って独自の Quicksilver の Actionを作ります。
【 ダイアログで指定したフォルダにファイルを複製する Action 】
1stPaneのObjectのファイル(フォルダ)を、ダイアログで指定したフォルダに複製を作るActionです。
Quicksilver には元々「Copy To...」Actionが有り、1stPaneのファイル・フォルダを、3rdPaneのフォルダに複製を作ることができます。

このスクリプトでは、保存先のフォルダを3rdPaneで指定するのではなく、
ダイアログで選択するようになります。
▽ ScriptEditor で開く
(* Duplicate To [...] *)
on open of theFile
set every_item to every item of theFile
tell application "Finder"
activate
try
set target_folder to (choose folder)
try
duplicate every_item to target_folder -- 複製
-- 保存先フォルダをFinderウインドウで表示
if window of target_folder exists then
set index of window of target_folder to 1
else
make new Finder window to target_folder
end if
on error error_message number error_number
-- 同名ファイルが存在した場合の処理
if error_number = -15267 then
set message to error_message & (return as text) & (return as text) & "置き換えますか?"
display dialog message with icon caution buttons {"Cancel", "Replace"} default button 1
if button returned of result is "Replace" then
duplicate every_item to target_folder with replacing -- 複製
-- 保存先フォルダをFinderウインドウで表示
if window of target_folder exists then
set index of window of target_folder to 1
else
make new Finder window to target_folder
end if
end if
else
display dialog error_message with icon caution buttons {"OK"} default button 1 giving up after 120
end if
end try
end try
end tell
end open
このスクリプトを「Duplicate To [...].scpt」とか適当な名前で
~/Library/Application Support/Quicksilver/Actions
に保存して、Quicksilver を再起動します。
そして、複製したいファイルを1stPaneのObjectに指定し、
2ndPaneで先程保存した「Duplicate To [...]」を選択して実行します。

すると、フォルダ選択のダイアログが表示されます。
ここで複製の保存先を選択します。

これで、ファイルが複製されます。
このときに、保存先のフォルダをFinderウインドウで表示します。
このActionは、Quicksilver のインターフェイス上で操作しようとすると、かえって面倒で、「Copy To...」Actionの方が確実に使い勝手がいいです。

しかしTriggerに左のように登録しておくと、使い勝手がよくなります。
・Object「Finder Selection」
・Action「Duplicate To [...]」
※「Finder Selection」は、Finderの最前面ウインドウで選択しているものを代用するProxy Objectです。
これをホットキーで登録すると、
Finderでファイル選択 → ホットキー → ダイアログで保存先を指定 → 複製
といった感じで操作できます。
Abracadabra Triggers でマウスジェスチャに登録して使えば、すべてマウス操作でできます。
Quicksilver のインターフェイスより、使い慣れたダイアログで操作する方がやり易いと感じるならば、このActionはけっこう使えます。
「Save Command to File...」Actionを使ってコマンドをファイルとして保存して、アプリケーションのようなものを作っておくと便利です。
まず、Quicksilver で下のように1stPaneで「Finder Selection」、2ndPaneで「Duplicate To [...]」とします。

この状態で control+return を押してCommand Objectにし、2ndPaneで「Save Command to File...」、3rdPaneで保存先フォルダを指定して実行します。

そうすると、指定したフォルダに
「Finder Selection (Duplicate To [...]).qscommand」
というファイルが作られます。

これをFinderウインドウのツールバーなどに登録します。
ファイルを選択し、ツールバーをクリックして実行すると、保存先フォルダの選択ダイアログが開き、ファイルを複製することができます。

もし、なにも選択していない状態だと、最前面のFinderウインドウのフォルダが複製されます。
Droplet Itemを使えば、ファイルをドラッグ&ドロップで起動するドロップレットアプリケーションを作ることができます。
作り方は上記の場合と同じく「Save Command to File...」Actionを使います。

「Finder Selection」が「Droplet Item」に変わるだけです。
これで作成された「Droplet Item (Duplicate To [...]).app」をFinderウインドウのツールバーやDockに登録して、ファイルをドラッグ&ドロップで複製の保存先フォルダを選択するダイアログが表示されます。

まあ、ドロップレットアプリケーションにするなら、Quicksilver を使わずに、AppleScriptの最初の「
on open of theFile
」の「of
」をとって
「
on open theFile
」
として、アプリケーションバンドル形式などで保存すれば、ドロップレットアプリケーションになります。
【 ダイアログで指定したフォルダにファイルを移動する Action 】
1stPaneのObjectのファイル(フォルダ)を、ダイアログで指定したフォルダに
移動するものです。
使い方などは上記の「Duplicate To [...]」と同じなので、省きます。
▽ ScriptEditor で開く
(* Move To [...] *)
on open of theFile
set every_item to every item of theFile
tell application "Finder"
activate
try
set target_folder to (choose folder)
try
move every_item to target_folder -- 移動
-- 移動先フォルダをFinderウインドウで表示
if window of target_folder exists then
set index of window of target_folder to 1
else
make new Finder window to target_folder
end if
on error error_message number error_number
-- 同名ファイルが存在した場合の処理
if error_number = -15267 then
set message to error_message & (return as text) & (return as text) & "置き換えますか?"
display dialog message with icon caution buttons {"Cancel", "Replace"} default button 1
if button returned of result is "Replace" then
move every_item to target_folder with replacing -- 移動
-- 移動先フォルダをFinderウインドウで表示
if window of target_folder exists then
set index of window of target_folder to 1
else
make new Finder window to target_folder
end if
end if
else
display dialog error_message with icon caution buttons {"OK"} default button 1 giving up after 120
end if
end try
end try
end tell
end open
違うボリュームにファイルを移動するときは、自動的に複製になってしまいます。
【 ダイアログで指定したフォルダにファイルのエイリアスを作る Action 】
1stPaneのObjectのファイル(フォルダ)のエイリアスを、ダイアログで指定したフォルダに保存するものです。
使い方などは上記の「Duplicate To [...]」と同じなので、省きます。
▽ ScriptEditor で開く
(* Make Alias At [...] *)
on open of theFile
set every_item to every item of theFile
tell application "Finder"
activate
try
set target_folder to (choose folder)
try
make new alias file at target_folder to every_item -- エイリアス
-- エイリアス保存先フォルダをFinderウインドウで表示
if window of target_folder exists then
set index of window of target_folder to 1
else
make new Finder window to target_folder
end if
on error error_message number error_number
display dialog error_message with icon caution buttons {"OK"} default button 1 giving up after 120
end try
end try
end tell
end open
この記事では Quicksilver B54(3815) を使用しています。
最近は Quicksilver B55 を使っていましたが、このB55では「Droplet Item」を使ってドロップレットアプリケーションを作るとうまく機能しないため。
それに頻繁にクラッシュするので、B54(3815)に戻しました。
(関連記事)
Quicksilver/ AppleScript で Action を作る(1)
Quicksilver/ AppleScript で Action を作る(2)
Quicksilver/ AppleScript で Action を作る(3)
Quicksilver --- 基本的な概略説明
Quicksilver/ 基本的な使用例
Quicksilver/ Catalogの設定
Quicksilver/ Actionについて(1)
Quicksilver/ Actionについて(2)
Quicksilver/ Actionについて(3)
Quicksilver/ Actionについて(4)- Command Objects
Quicksilver/ Triggers の説明(1)
Quicksilver/ Triggers の説明(2)
Quicksilver/ Plug-ins について
Quicksilver/ Proxy Objects について
Quicksilver/ Triggers の説明(3)- Mouse Triggers
Quicksilver/ Triggers の説明(4)- Abracadabra Triggers
Quicksilver/ ショートカットまとめ
すべてのQuicksilver記事のリンクは『Quicksilver』の(関連記事)にあります。
▽同じ「タグ」が付いた関連記事
trackback URL