2

I am looking for a universal builtin command that resizes Xterm based terminals.

This is some sort of command that won't make a new window, that I won't need to include in the file that these terminals start up with.

I want to make an app that will open in a 60x30 frame, but only after you run the command

myapp run

I don't want my terminal to always open at 30x60, I just want it to resize when I run myapp.

Blue Ice
  • 557

3 Answers3

3

There is an ANSI escape sequence that most terminals (include Terminal.app) should accept:

$ echo -e "\e[8;30;60t"

This will resize your terminal to have 30 rows and 60 columns (swap the 30 and 60 if I've misunderstood the dimensions you want).

As long as this string is written to the terminal, you can use it from anywhere. You can make it part of myapp, or create a shell function as a wrapper:

myapp () {
    echo -e "\e[8;30;60t"
    command myapp "$@"
}
chepner
  • 7,041
2

I don't have a Mac so I can't try this but wmctrl is a UNIX app so it should work for OSX as well. Try something like:

 wmctrl -r :ACTIVE: -e 5,-1,-1,660,540
        -----------   -- -- -- --- ---
             |         | |  |   |   |---> Window height
             |         | |  |   |-------> Window width             
             |         | |  |-----------> Window Y coordinates
             |         | |--------------> Window X coordinates
             |         |----------------> Gravity
             |--------------------------> Apply to the active window

Gravity can be one of (source):

  • NorthWest (1)
  • North (2),
  • NorthEast (3),
  • West (4),
  • Center (5),
  • East (6),
  • SouthWest (7),
  • South (8),
  • SouthEast (9)
  • Static (10).

A gravity of 0 indicates that the Window Manager should use the gravity specified in WM_SIZE_HINTS.win_gravity.

terdon
  • 54,564
1

You could try AppleScript. Here an example to tun vim:

#!/bin/sh 
# Script runvim.sh
osascript  <<EOF
tell app "Terminal"
  set number of rows of first window to 34
  set number of columns of first window to 96
  set custom title of first window to "vim"
end tell
EOF
vim $@

This is built-in but you might have to find out how to differentiate between Terminal and iTerm2. Either you know what your users want to use or you let them pick (or something more clever :-)).

rfindeis
  • 111