|
|
This page features examples of AppleScript available in 2.1 and earlier. Please see <a href="https://iterm2.com/applescript.html">Applescript for iTerm2 2.9+</a> for the 3.0 syntax.</a>
|
|
|
|
|
|
<pre>
|
|
|
|
|
|
|
|
|
tell application "iTerm"
|
|
|
activate
|
|
|
|
|
|
-- Create a new terminal window...
|
|
|
set myterm to (make new terminal)
|
|
|
|
|
|
-- ... and go on within this one.
|
|
|
tell myterm
|
|
|
-- Set the terminal size constraints.
|
|
|
set number of columns to 30
|
|
|
set number of rows to 30
|
|
|
|
|
|
-- Array/List which will hold all our sessions (empty
|
|
|
-- by default OFC).
|
|
|
set sessionList to {}
|
|
|
|
|
|
-- Create a few blank new sessions (will be replaced by
|
|
|
-- automatic calculations later, so that we'll have a
|
|
|
-- nice bar full with new tabs.)
|
|
|
repeat with i from 1 to 2 by 1
|
|
|
launch session "Default"
|
|
|
end repeat
|
|
|
|
|
|
-- DEBUG: print the session list.
|
|
|
return sessionList
|
|
|
|
|
|
end tell
|
|
|
|
|
|
-- set the bounds of the first window to {w, x, y, z}
|
|
|
end tell
|
|
|
</pre>
|
|
|
|
|
|
|
|
|
<pre>
|
|
|
|
|
|
tell application "iTerm"
|
|
|
activate
|
|
|
|
|
|
-- close the first session
|
|
|
terminate the first session of the first terminal
|
|
|
|
|
|
-- make a new terminal
|
|
|
set myterm to (make new terminal)
|
|
|
|
|
|
-- talk to the new terminal
|
|
|
tell myterm
|
|
|
|
|
|
-- make a new session
|
|
|
set mysession to (make new session at the end of sessions)
|
|
|
|
|
|
-- set size
|
|
|
set number of columns to 100
|
|
|
set number of rows to 50
|
|
|
|
|
|
-- talk to the session
|
|
|
tell mysession
|
|
|
|
|
|
-- set some attributes
|
|
|
set name to "tcsh"
|
|
|
set foreground color to "red"
|
|
|
set background color to "blue"
|
|
|
set transparency to "0.6"
|
|
|
|
|
|
-- execute a command
|
|
|
exec command "/bin/tcsh"
|
|
|
|
|
|
end tell -- we are done talking to the session
|
|
|
|
|
|
-- we are back to talking to the terminal
|
|
|
|
|
|
-- launch a default shell in a new tab in the same terminal
|
|
|
launch session "Default Session"
|
|
|
|
|
|
-- launch a saved session from the addressbook.
|
|
|
launch session "Root Shell"
|
|
|
-- select the previous session
|
|
|
select mysession
|
|
|
-- get the tty name of a session
|
|
|
set myttyname to the tty of the first session
|
|
|
-- refer to a session by its tty/id
|
|
|
tell session id myttyname
|
|
|
set foreground color to "yellow"
|
|
|
end tell
|
|
|
|
|
|
end tell
|
|
|
|
|
|
-- talk to the first terminal
|
|
|
tell the first terminal
|
|
|
|
|
|
-- launch a default shell in a new tab in the same terminal
|
|
|
launch session "Default Session"
|
|
|
|
|
|
tell the last session
|
|
|
|
|
|
-- write some text
|
|
|
write text "cd Projects/Cocoa/iTerm"
|
|
|
-- write the contents of a file
|
|
|
write contents of file "/path/to/file/"
|
|
|
|
|
|
end tell
|
|
|
|
|
|
end tell
|
|
|
|
|
|
-- reposition window and name it
|
|
|
set the bounds of the first window to {100, 100, 700, 700}
|
|
|
set the name of the first window to "A Window Title"
|
|
|
|
|
|
|
|
|
end tell
|
|
|
</pre>
|
|
|
|
|
|
This finds and selects a tab named "Special".
|
|
|
|
|
|
<pre>
|
|
|
tell application "iTerm"
|
|
|
activate
|
|
|
set myterm to (current terminal)
|
|
|
tell myterm
|
|
|
repeat with mysession in sessions
|
|
|
tell mysession
|
|
|
set the_name to get name
|
|
|
if the_name contains "Special" then
|
|
|
select mysession
|
|
|
return
|
|
|
end if
|
|
|
end tell
|
|
|
end repeat
|
|
|
end tell
|
|
|
end tell
|
|
|
</pre>
|
|
|
|
|
|
Open tabs to various machines:
|
|
|
<pre>
|
|
|
(* set to the user of the box, ie "root" or "deployer" *)
|
|
|
set box_user to "user"
|
|
|
(* Add the hostnames or IP's of the boxes to connect to. As many as you need. *)
|
|
|
set my_boxes to {"box1", "box2", "box3"}
|
|
|
|
|
|
tell application "iTerm"
|
|
|
activate
|
|
|
set t to (make new terminal)
|
|
|
tell t
|
|
|
(* Loop over the boxes, create a new tab and connect. *)
|
|
|
repeat with box in my_boxes
|
|
|
activate current session
|
|
|
launch session "Default Session"
|
|
|
tell the last session
|
|
|
set conn to "ssh " & box_user & "@" & box
|
|
|
write text conn
|
|
|
end tell
|
|
|
end repeat
|
|
|
end tell
|
|
|
end tell
|
|
|
</pre> |
|
|
\ No newline at end of file |