For years I've been using the following AppleScript to open txt files in vim in iTerm2, but since iTerm 2.9.2 (aka iTerm3) it's broken. Could anyone advise how to update this AppleScript so it works again?
on run {input, parameters}
if (count of input) > 0 then
tell application "System Events"
set runs to false
try
set p to application process "iTerm"
set runs to true
end try
end tell
tell application "iTerm"
activate
if (count of terminals) = 0 then
set t to (make new terminal)
else
set t to current terminal
end if
tell t
tell (make new session at the end of sessions)
exec command ("vim \"" & POSIX path of first item of input as text) & "\""
end tell
if not runs then
terminate first session
end if
end tell
end tell
end if
end run
I originally copied the script from http://earthwithsun.com/questions/283418/how-can-i-make-terminal-vim-my-default-editor-application-in-mac-os-x but I have no AppleScript experience whatsoever.
Any help most appreciated! B
Vanilla Vim 1 Opening files from the Command line. ... 2 Switching files after opening (Buffers) Vim will open all three files in ‘buffers’ but you might not see them (see this article for help setting up a plugin that makes ... 3 Open files with :edit command. ... 4 Netrw the built in file browser. ...
Vim has an auto completion engine called “wildmenu” (activate it with :set wildmenu or add set wildmenu to your .vimrc). With the wildmenu setting active while typing a file path press <Tab> and vim will autocomplete the path.
To do this we need to use Finder to find a file of each type you want to default to open with Neovim in iTerm. Then we will change the association in MacOS for that file that might already exist to point to our new application.
Using @dusty's link, I recommend that you change the entire code section of your Run AppleScript Action to this:
on run {input, parameters}
tell application "iTerm"
activate
if (count of windows) = 0 then
set t to (create window with default profile)
else
set t to current window
end if
tell t
tell current session
write text ("vim \"" & POSIX path of first item of input as text) & "\""
end tell
end tell
end tell
end run
It seems to work on my machine, but I never use vim, so I am not sure if this will give you precisely what you want.
Good luck,
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With