How to open multiple Iterm windows on startup
Published by Nicholas Dunbar on February 10th, 2016
Find your self having to run a server or turn on some sort of process every time you open up your development environment? The script bellow will help you set up your own custom default tabs in iterm running what ever scripts you want when the window initializes. This script opens up two windows one of which has two tabs. The two tabs are for processes like running a server or a build process like grunt. The second window is just a general terminal so you can use the command line.
1.) Copy the script at the bottom into the following file ~/Library/Application Support/iTerm/AutoLaunch.scpt
2.) Configure the name of the first tab and the command you want to run.
Example in the script:
set name to "localhost:8000"
write text "cd ~/ && npm start"
3.) Configure the name of the second tab and the command you want to run.
Example in the script:
set name to "grunt watch"
write text "cd ~/ && grunt watch"
4.) if you want more than 3 tabs copy the following:
-- make a new session
launch session "Default"
set mysession to (current session)
-- talk to the session
tell mysession
-- set some attributes
set name to "grunt watch"
launch session "Default"
set mysession to (current session)
-- talk to the session
tell mysession
-- set some attributes
set name to "grunt watch"
-- execute a command
write text "cd ~/ && grunt watch"
end tell -- we are done talking to the session
and paste it at — add more tabs here
5.) If you want
————————————————AutoLaunch.scpt————————————————
-- get the dimensions of the desktop, set up few variables
tell application "Finder"
set displayAreaDimensions to bounds of window of desktop
set x1 to item 1 of displayAreaDimensions
set y1 to item 2 of displayAreaDimensions
set x2 to item 3 of displayAreaDimensions
set y2 to item 4 of displayAreaDimensions
end tell
set width to x2 - x1
set height to y2 - y1
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
activate current session
launch session "Default"
set mysession to (current session)
-- 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 "localhost:8000"
-- execute a command
tell application "Finder"
set displayAreaDimensions to bounds of window of desktop
set x1 to item 1 of displayAreaDimensions
set y1 to item 2 of displayAreaDimensions
set x2 to item 3 of displayAreaDimensions
set y2 to item 4 of displayAreaDimensions
end tell
set width to x2 - x1
set height to y2 - y1
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
activate current session
launch session "Default"
set mysession to (current session)
-- 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 "localhost:8000"
-- execute a command
write text "cd ~/ && npm start"
end tell -- we are done talking to the session
-- make a new session
launch session "Default"
set mysession to (current session)
-- talk to the session
tell mysession
-- set some attributes
set name to "grunt watch"
-- execute a command
write text "cd ~/ && grunt watch"
end tell -- we are done talking to the session
— add more tabs here
end tell
-- reposition window and name it
set the bounds of the first window to {x1 + 3 * (width / 4), y1 + 3 * (height / 4), x2, y2}
set the name of the first window to "Consoles"
-- make a new terminal
set myterm to (make new terminal)
-- talk to the new terminal
tell myterm
-- make a new session
activate current session
launch session "Default"
set mysession to (current session)
-- 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 "mrsparklepants"
-- execute a command
write text "echo 'start up script located in ~/Library/Application Support/iTerm/AutoLaunch.scpt'"
end tell -- we are done talking to the session
end tell
-- reposition window and name it
set the bounds of the first window to {x1 + 3 * (width / 4), y1, x2, y2 - (height / 4) - 23}
set the name of the first window to "Commands"
end tell