-
-
Save reyjrar/1769355 to your computer and use it in GitHub Desktop.
(* | |
* New-iTerm-Window.scpt | |
* | |
* Intended for use with QuickSilver | |
* I mapped option-y to running this script to create | |
* a new iTerm window on the current workspace | |
* | |
* Based on much Googling - very little "original" code here | |
* Comments/Suggestions to [email protected] | |
*) | |
if isAppRunning("iTerm") then | |
tell application "iTerm" | |
set myterm to (make new terminal) | |
tell myterm | |
set mysession to (make new session at the end of sessions) | |
tell mysession | |
exec command "/bin/bash -l" | |
end tell | |
end tell | |
activate | |
end tell | |
else | |
activate application "iTerm" | |
end if | |
(* Code from Dweller on | |
* http://codesnippets.joyent.com/posts/show/1124 | |
*) | |
on isAppRunning(appName) | |
tell application "System Events" to (name of processes) contains appName | |
end isAppRunning |
Thanks for the contribution, but I have a strange issue that I don't understand from watching the code. If I execute the script from the Automator, it behaves as expected but if a set keyboard shortcut and iTerm is not opened, it opens not one but two windows. Any idea?
I have, like you, looked at many examples spread around the internet, and the script I've come up with, taking inspirations for many sources, you included, is the following:
if application "iTerm" is running then
tell application "iTerm"
create window with default profile
end tell
else
activate application "iTerm"
end if
I have tested it running both via Alfred and Automator. One thing it has above your example and many of the ones on the internet is that, like @IvanParraga mention, if iTerm is not running, two windows are opened. With this script, that doesn't happen.
The only thing missing, really, is that if you already have iTerm open, and have a window on the space your currently on, and you run this script, the window already open will come to the front with the new window. This is a problem all the solution I have seen on the internet shares, and I haven't found a solution yet.
FWIW @ChrisBuchholz's version requires the iTerm 3 betas.
Thanks @ChrisBuchholz. Works a treat.
@ohammersmith: Indeed! Though, it's the iTerm 2 betas, right?
@ChrisBuchholz you saved my day!
I have modified the old version of "open terminal window in current folder"
`on run {input, parameters}
tell application "Finder"
set dir_path to quoted form of (POSIX path of (folder of the front window as alias))
end tell
CD_to(dir_path)
end run
on CD_to(theDir)
if application "iTerm" is running then
tell application "iTerm"
tell current window
create tab with default profile
tell current session
write text "cd " & theDir & ";clear;"
end tell
end tell
end tell
else
tell application "iTerm"
tell current window
tell current session
write text "cd " & theDir & ";clear;"
end tell
end tell
end tell
end if
activate application "iTerm"
end CD_to`
Thias was the old version. i dont remeber the source:
`on run {input, parameters}
tell application "Finder"
set dir_path to quoted form of (POSIX path of (folder of the front window as alias))
end tell
CD_to(dir_path)
end run
on CD_to(theDir)
tell application "iTerm"
tell current window
create tab with default profile
tell current session
write text "cd " & theDir & ";clear;"
end tell
end tell
end tell
end CD_to`
@ChrisBuchholz is simple and uncomplicated. Add it to a file, stick #!/usr/bin/osascript
at the top, chmod +x
it and then call it from your favorite automation utility. in my case, khd
.
error "iTerm got an error: current tab of current window doesn’t understand the “write” message." number -1708 from current tab of current window
@SwankyLegg activate does