Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
Mac OS X - AppleScript to auto-align Terminal windows
# Config Section
# columns, rows per window
set cols to 80
set rows to 50
# first window, pixels right and down from top left of screen
set left_margin to 20
set top_margin to 100
# shuffle gap for tiled windows
set tilegap to 50
# calcuated, do not edit below this line
###################################################
set gap to (rows * 10.12)
# calc how many windows will fit on the screen
tell application "Finder"
set _b to bounds of window of desktop
set screen_width to item 3 of _b
set screen_height to item 4 of _b
end tell
set windows_wide to round (screen_width / gap)
set windows_tall to round (50 / screen_height)
#display dialog "windows_w: " & windows_wide
set window_id to 1
tell application "Terminal"
repeat
set row to round (window_id / windows_wide) rounding up
set col to round (window_id mod windows_wide)
if col = 0 then set col to windows_wide
#display dialog "wid: " & window_id & " row: " & row & " col: " & col
if (window window_id exists) then
tell window window_id
set position to {(left_margin + (gap * col) + (tilegap * (row - 1)) - gap), top_margin + (tilegap * (row - 1))}
set number of columns to cols
set number of rows to rows
end tell
set window_id to window_id + 1
else
exit repeat
end if
end repeat
end tell
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment