2019独角兽企业重金招聘Python工程师标准>>>
AppleScript support for SplitPanes
来自:http://code.google.com/p/iterm2/issues/detail?id=559
Reported by samantha... @gmail.com ,
Jan 29, 2011
Hi,
I would like to be able to script the creation of SplitPanes which I find very useful. Ideally, would like to be able to name each pane, launch command in each pane upon creation and decide if the pane is split vertically or horizontally
Congratulations for what's already been achieved with iTerm2.
@samo9789
May 14, 2011
#1 [email protected]
I've been using the following applescript to setup panes. Perhaps it will be useful to others until better support is available...
osascript <
Jun 1, 2011
#2 [email protected]
Thanks for sharing this tip. I added it (crediting you) to my blog post about scripting iTerm2: http://www.worldgoneweb.com/2011/iterm2-advanced-features/#comment-20560
Nov 27, 2011
#3 [email protected]
+1 on this one. I'm trying to script opening up 4 panes (2x2), and having each one SSH into a different machine. However, I can't reference any of the new sessions while running the script from within iTerm2.
Dec 5, 2011
Project Member #4 [email protected]
(No comment was entered for this change.)
Blockedon: 152
Mar 20, 2012
#5 [email protected]
Some time ago, I wrote a ruby app that splits stuff for you and connects over ssh to different machines. Might be interesting: https://github.com/wouterdebie/i2cssh
May 8, 2012
#6 [email protected]
It seems that the sessions implicitly created by simulation the keystrokes are appended to the end of the sessions list:
tell application "iTerm"
activate
tell (make new terminal)
set number of columns to 50
set number of rows to 50
tell (launch session "initial_session") to write text "echo 'SESSION 1'"
tell application "System Events" to keystroke "D" using command down
tell last item of sessions to write text "echo 'SESSION 2'"
tell application "System Events" to keystroke "d" using command down
tell last item of sessions to write text "echo 'SESSION 3'"
end tell
end tell
Jun 14, 2012
#7 [email protected]
You can create 4 panes in a single tab like this by using the shortcut option-command-arrowup (key code 126):
tell i term application "System Events" to key code 126 using {command down, option down}
tell i term application "System Events" to keystroke "d" using command down
tell last item of sessions to write text "echo 'SESSION 4'"
This works, however "the last item of sessions" doesn't follow. The result is that SESSION 4 is shown in the pane of SESSION 3.
Any ideas?
Jun 14, 2012
#8 [email protected]
Ok, I already figured out. Apparently, when you switch panes with option-command-arrows and create a new pane, the number changes. The new session after session 3 becomes session 2. So to solve the issue for session 4, you can't use 'the last item' but specify item 2. The code then becomes:
tell application "iTerm"
activate
tell (make new terminal)
tell (launch session "initial_session") to write text "echo 'SESSION 1'"
tell i term application "System Events" to keystroke "D" using command down
tell last item of sessions to write text "echo 'SESSION 2'"
tell i term application "System Events" to keystroke "d" using command down
tell last item of sessions to write text "echo 'SESSION 3'"
tell i term application "System Events" to key code 126 using {command down, option down}
tell i term application "System Events" to keystroke "d" using command down
tell i term application "System Events" to key code 126 using {command down, option down}
tell item 2 of sessions to write text "echo 'SESSION 4'"
end tell
end tell
Mar 21, 2013
#9 [email protected]
Hi,
I begin in writing appleScript. I think I wrote a better script to store the session and then be able to launch command in the pane you want to
tell application "iTerm"
activate
tell (current terminal)
copy id of current session to session1
tell i term application "System Events" to keystroke "d" using command down
copy id of last item of sessions to session2
tell i term application "System Events" to keystroke "D" using command down
copy id of last item of sessions to session3
repeat with theItem in sessions
if id of theItem is session1 then
tell theItem to write text "echo " & (session1)
end if
end repeat
repeat with theItem in sessions
if id of theItem is session2 then
tell theItem to write text "echo " & (session2)
end if
end repeat
repeat with theItem in sessions
if id of theItem is session3 then
tell theItem to write text "echo " & (session3)
end if
end repeat
end tell
end tell
I try to simplify it whith using `tell the first item of sessions whose id is session1` but it didn't work...
Apr 18, 2013
#10 [email protected]
Hey, if anyone's interested here's an applescript I wrote that more or less inteligently splits a new iterm window and connects to an ad-hoc number of ssh sessions (sort of like cssh) https://gist.github.com/bmfurtado/5392276 enjoy.
Jul 21, 2013
#11 [email protected]
https://github.com/luismartingil/scripts/blob/master/iterm_launcher02.applescript #!/usr/bin/osascript
-- Applescript to launch iterm2 terminals/tabs with configurable:
-- ~ List of commands
-- ~ Color
-- ~ Name
-- ~ Transparency
-- ~ Zoom out
-- ~ Split behavior horizontal(h) or vertical(v) :: (h, v)
--
-- Run from terminal with `osascript` or just ./<