17
15

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

More than 5 years have passed since last update.

ダブルクリックで iTerm2 上の Vim を開く

Last updated at Posted at 2015-06-29

普段、 iTerm2 上で Vim を使っているのですが、 Finder 上のファイルをちょっと編集するのにダブルクリックで Vim を開きたいと思ったので、AppleScript でランチャーアプリを作成しました。

Automator を開き、 AppleScript を選択して以下のコードを VimLauncher.app という名前で保存

2016/06/09 スクリプトを修正しました。

VimLauncher.app
on run argv
	
	set the_path to POSIX path of (item 1 of argv)
	set cmd to "vim " & escapeSpace(the_path)
	
	if isAppRunning("iTerm2") then
		
		tell application "iTerm"
			activate
			select last window
			tell current window
				set newtab to (create tab with default profile)
				tell newtab
					tell current session
						write text cmd
					end tell
					activate
				end tell
			end tell
		end tell
	else
		activate application "iTerm"
		tell application "iTerm"
			tell current window
				tell current session
					write text cmd
				end tell
				activate
			end tell
		end tell
	end if
	
end run

on isAppRunning(appName)
	tell application "System Events" to (name of processes) contains appName
end isAppRunning

on escapeSpace(myText)
	set oldDel to AppleScript's text item delimiters
	set AppleScript's text item delimiters to " "
	set myText to every text item of myText
	set AppleScript's text item delimiters to "\\ "
	set myText to myText as string
	set AppleScript's text item delimiters to oldDel
	return myText
end escapeSpace

あとは、特定の拡張子のデフォルトアプリケーションを作成した VimLauncher.app に設定します。


このあたりを参考にさせていただきました。

17
15
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
17
15

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?