# Keyboard Maestroで「Path Finderで選択したファイルを特定アプリで開く」プラグインを作成する方法 URL: https://webrandum.net/keyboard-maestro-open-pathfinder-selection/ 公開日: 2019-12-05 更新日: 2019-12-05 カテゴリー: 作業効率化 タグ: Keyboard Maestro 出典: Webrandum(著者: サイトウ マサカズ) Keyboard Maestroで、Finderで選択したファイルを特定アプリで開きたいときは「Open the Finder Selection」アクションを使うと簡単に実現できます。 しかし、Path Finderを使っている人は変数を使ったり条件分岐やAppleScriptを組み合わせてようやく実現できます。 マクロが長くなってしまうと見通しが悪くなってしまいますし、時間が経ってから見返したときに、何をやっているのか分からなくて混乱してしまいます。 そこで、Third Party Plug InsでPath Finderで選択したファイルを特定アプリで開けるようにしてみました。 ## Third Party Plug Insについて Third Party Plug Insの作り方や必要ファイルは[過去に紹介](https://webrandum.net/keyboard-maestro-make-third-party-plug-ins/)したので、そちらをご覧ください。 [![](https://www.google.com/s2/favicons?domain=webrandum.net)Webrandum![](//webrandum.net/mskz/wp-content/uploads/2019/11/eyecatch-21.jpg)Keyboard MaestroのThird Party Plug Insの作り方https://webrandum.net/keyboard-maestro-make-third-party-plug-insKeyboard MaestroでThird Party Plug Insを作ってみたかったので、作り方をまとめました。基本の設定必要ファイルKeyboard MaestroのThird Party Plug Insに必要なファイルは下記の3つです。ファイル入力内容スクリプトファイルAppleScriptなら.scptファイル、シェルスクリプトなら.shを用意。中にプラグインの処理を書くIcon.pngアクションに表示されるアイコン画像(64px × 64pxがベスト)Keyboard Maestro Action.plistアクションのタイトルや、入力項目を設定するファイルこの3つを用意します。Keyboard Maestro Action.plistの最...](https://webrandum.net/keyboard-maestro-make-third-party-plug-ins) ### Keyboard Maestro Action.plist 入力欄ではTokenStringを使用して、アプリ名を入力するようにします。 本当は「Open the Finder Selection」アクションと同じように、アプリ一覧が表示されるセレクトボックスを表示させられると良いのですが、Third Party Plug Insでは用意されていませんでした。 ``` Name Open the Path Finder Selection Script Action.scpt Icon Icon.png Title Open Path Finder Selection '%Param%Open Path Finder selection with%' Parameters Label Open Path Finder selection with Type TokenString ``` ### Action.scpt 入力欄の「Open Path Finder selection with」の値を取得したいので、「set appName to system attribute “KMPARAM_Open_Path_Finder_selection_with”」で`appName`変数に入力した値を入れています。 あとは、`appName`をもとにアプリを取得して、Path Finderで選択しているファイルを開くだけです。 ``` set finderSelection to "" set theTarget to "" set appName to system attribute "KMPARAM_Open_Path_Finder_selection_with" set appPath to path to application appName set defaultTarget to (path to home folder as alias) tell application "Path Finder" set theTarget to {} repeat with pfItem in (get selection) set the end of theTarget to POSIX path of pfItem end repeat end tell tell application appName open theTarget end tell ``` ## 使い方 使うときはThird Party Plug Insに追加されている「Open the Path Finder Selection」をマクロに追加して、入力欄にアプリ名を入力すればOKです(正確に入力する必要があります)。 ![](https://webrandum.net/mskz/wp-content/uploads/2019/12/image_1-4.png) ## まとめ やっていることは、今まで使っていたAppleScriptを外部ファイル化して、Keyboard Maestroの入力欄と繋げているだけなので、コードの関数化に近いです。 今まで複数のアクションを使っていたことが1つにまとめられて、管理もしやすくなりました。