LoginSignup
3
6

More than 3 years have passed since last update.

Macのファインダーから右クリックでファイルをvimで開く

Posted at

やりたいこと

表題の通りです。
普段は、ファインダーからアクセスしたファイルをVSCodeで開いているのですが、ふとしたきっかけで、
「Macのファインダーから右クリックでファイルをvimで開く」のはどうしたらいいか調べたので、そのメモです。

同様の記事は、すでにたくさんありますが、結果的に初めてAppleScriptを使うことになったので、書いておきます。

流れ

  • Automatorを使う
  • Automatorで新規作成 -> AppleScriptを実行 で、スクリプトを記述
  • アプリケーション形式で保存(名前はTerminalVimとか)
  • 対象のファイルを右クリック
    • 「このアプリケーションで開く」で、作成したアプリケーションを選択

Automatorで記載.png

記載内容

見よう見まねで試しましたが、いったんはこのような形で落ち着きました。
iTermで開く場合は、"Terminal" を "iTerm" に置き換えます。

on run {input}
    set the_path to POSIX path of input
    set cmd to "vim " & quoted form of the_path & "; exit"
    tell application "System Events" to set terminalIsRunning to exists application process "Terminal"
    tell application "Terminal"
        if terminalIsRunning is true then
            do script with command cmd
        else
            do script with command cmd in window 1
        end if
        activate
    end tell
end run

参考

3
6
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
3
6