> ## Content Index
> Fetch the complete content index at: https://www.bagz.fr/llms.txt
> Use this file to discover other available public pages before exploring further.

# iTerm - Automatic mutliple panes with AppleScript
- URL: https://www.bagz.fr/iterm-automatic-mutliple-panes-with-applescript/
- Published: 2017-01-02T10:24:12.000Z
- Updated: 2026-09-29T09:12:02.000Z
- Author: bgazui
- Tags: MacOS, #Migrated-1790668826633, #wp, #wp-post, #Import 2026-09-29 08:00

It's often very useful to automate opening of multi panes with iTerm to execute many commands or getting access to many servers at the same time. This can be done through AppleScript.

You can copy this script and save it as *multi-panes.scpt*

---

#! /usr/bin/osascript  
  
\-- List actions to perform  
set actions to {¬  
 {action:"echo 'I am the window 1'"}, ¬  
 {action:"echo 'I am the window 2'"}, ¬  
 {action:"echo 'I am the window 3'"}, ¬  
 {action:"echo 'I am the window 4'"}, ¬  
 {action:"echo 'I am the window 5'"}, ¬  
 {action:"echo 'I am the window 6'"}, ¬  
 {action:"echo 'I am the window 7'"}, ¬  
 {action:"echo 'I am the window 8'"} ¬  
 }  
\-- Count number of actions  
set num\_actions to count of actions  
  
\-- Set cols and lines  
set num\_cols to round (num\_actions ^ 0.5)  
set num\_lines to round (num\_actions / num\_cols) rounding up  
  
\-- Start iTerm  
tell application "iTerm"  
 activate  
  
 \# Create new tab  
 tell current window  
 create tab with default profile  
 end tell  
  
 \-- Prepare horizontal panes  
 repeat with i from 1 to num\_lines  
 tell session 1 of current tab of current window  
 if i < num\_lines then  
 split horizontally with default profile  
 end if  
 end tell  
 end repeat  
  
 \-- Prepare vertical panes  
 set sessid to 1  
 repeat with i from 1 to num\_lines  
 if i is not 1 then set sessid to sessid + num\_cols  
 if i is not num\_lines or num\_actions is num\_cols \* num\_lines then  
 set cols to num\_cols - 1  
 else  
 set cols to (num\_actions - ((num\_lines - 1) \* num\_cols)) - 1  
 end if  
 repeat with j from 1 to (cols)  
 tell session sessid of current tab of current window  
 split vertically with default profile  
 end tell  
 end repeat  
 end repeat  
  
 \-- Execute actions  
 repeat with i from 1 to num\_actions  
 tell session i of current tab of current window  
 write text (action of item i of actions)  
 end tell  
 end repeat  
end tell

---

Then, you just have to call the script directly:

\# osascript multi-panes.scpt  

And here is what you're getting:

![](https://www.bagz.fr/content/images/Screen-Shot-2016-12-30-at-10.19.28.png) 

Feel free to add/remove/update the actions as needed!