-
-
Save brablc/b2f40c2f652e420484d2 to your computer and use it in GitHub Desktop.
on run {input, parameters} | |
set cmd to "vim -c startinsert" | |
if input is not in {} then | |
set myPath to POSIX path of input | |
set cmd to "vim " & quote & myPath & quote | |
end if | |
tell application "iTerm" | |
activate | |
set myTerm to (current terminal) | |
tell myTerm | |
set mySession to (make new session at the end of sessions) | |
tell mySession to exec command cmd | |
end tell | |
end tell | |
end run |
@mstroeck Is it necessary to update something from the script?
I've tried it but automator shows me an error
Modified to work in Sierra: https://gist.github.com/charlietran/43639b0f4e0a01c7c20df8f1929b76f2
@charlietran Thank you very much, I commented on your gist for some suggestions :)
Ok guys I took the challenge as well and here is my gist : https://gist.github.com/chaadow/5e8ed49c333008eec0c3ced07451ee48
It works for El Capitan.
It handles 2 scenarios basically :
- When Iterm is not open :
- It doesn't create a second unnecessary window, since it knows that it's startup
- It tells the current session to run vim with the appropriate POSIX path
- When iTerm is open :
- If there are no windows open ( This is the case when you have closed all windows but iTerm is still open, kinda frequent for me)
- It creates a window with the default profile
- It runs the vim command
- If there is at least one window open
- It creates a new tab so that it doesn't override the current tab of the window
- It runs the vim command
- If there are no windows open ( This is the case when you have closed all windows but iTerm is still open, kinda frequent for me)
Even though the script feels repetitive, this is the only and simplest way I found to handle most of the edge cases.
Alternatively, according to the iterm documentation, there is a is at shell prompt
option, that allows to know if the current session if "free", so we can run the vim command without the need of creating a new tab each time.
However it requires installing the shell integration utiliites inside of iTerm, and this is not a "simple solution".
Cheers.
This crashes for me if iTerm is not currently running, or it's running but has no windows open. I modified it to work for me on Mac OS X El Capitan: