Skip to content

Instantly share code, notes, and snippets.

@kennyng
Last active January 29, 2017 10:25
Show Gist options
  • Save kennyng/62414e7153af1d6a5097 to your computer and use it in GitHub Desktop.
Save kennyng/62414e7153af1d6a5097 to your computer and use it in GitHub Desktop.
Open files with Vim (command-line) in default OSX Terminal (VimTerminal) and iTerm (VimTerm).
on run {input, parameters}
if (count of input) > 0 then
tell application "iTerm"
if (count of terminals) = 0 then
activate
end if
tell (current terminal)
tell (launch session "Default")
write text "vim " & (POSIX path of first item of input as text)
end tell
end tell
end tell
end if
end run
on open this_file
tell application "System Events"
if (count (processes whose name is "Terminal")) is 0 then
tell application "Terminal"
activate
do script with command "vim " & (POSIX path of this_file) in front window
end tell
else
tell application "Terminal"
activate
tell application "System Events" to tell process "Terminal" to keystroke "t" using command down
do script with command "vim " & (POSIX path of this_file) in selected tab of the front window
end tell
end if
end tell
end open
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment