Apple - Can a Terminal window be resized with a Terminal command?

Yes. Terminal supports escape sequences for manipulating windows, including the size and position, layering, and minimizing. Dimensions can be expressed in pixels or characters. See Xterm Control Sequences for details (search for “Window manipulation”; if you’re not familiar with the notation, “CSI” stands for “Control Sequence Introducer”, which is ESC [).

For example, this shell command will set the window to 100x50 characters:

printf '\e[8;50;100t'

Minimize the window for a few seconds, then restore it:

printf '\e[2t' && sleep 3 && printf '\e[1t'

Move the window to the top/left corner of the display:

printf '\e[3;0;0t'

Zoom the window:

printf '\e[9;1t'

Bring the window to the front (without changing keyboard focus):

printf '\e[5t'

Enabling the Control Sequences in Terminal Emulators

Some terminal emulators ignore these control sequences by default and require configuration to enable them.

To enable these in XTerm, set the following resource to true:

allowWindowOps

To enable these in iTerm2, deselect the following preference:

Preferences > Profiles > [profile] > Terminal > Disable session-initiated window resizing


Use /usr/X11/bin/resize.

resize -s 30 80 will give you 30 rows and 80 columns.

resize -s 30 0 will give you 30 rows and full columns.

resize -s 0 80 will give you full rows and 80 columns.


You could always use AppleScript:

setwidth() { osascript -e "tell app \"Terminal\" to tell window 1
set b to bounds
set item 3 of b to (item 1 of b) + $1
set bounds to b
end"; }

Tags:

Terminal