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.

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.

3
  • 2
    @BlueIce You will not find a built in for this. Bash has no knowledge of the GUI, why should it?
    – terdon
    Mar 31 '13 at 16:51
  • 3
    This won't work on OS X, since its Terminal app isn't based on X11.
    – Daniel Beck
    Mar 31 '13 at 17:42
  • Edited question appropriately.
    – Blue Ice
    Mar 31 '13 at 19:07
2

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 "$@"
}
5
  • I am looking for an xterm solution. This doesn't seem to work on xterm on linux.
    – Blue Ice
    Apr 3 '13 at 2:13
  • Odd; it's a standard escape sequence. This is easier to type, maybe it will work better for you: resize -s 30 60. I think it essentially outputs the same characters given in the answer.
    – chepner
    Apr 3 '13 at 2:30
  • This also doesn't seem to work. The only resize command that I've gotten to work in xterm is xterm -geometry 30x60, but this just opens an entirely new window with those dimensions.
    – Blue Ice
    Apr 3 '13 at 12:40
  • The only other thing I can think of is that the allowWindowOps resource is set to false, and disallowedWindowOps contains 8 or SetWinSizeChars, which would prevent the escape sequence from working.
    – chepner
    Apr 3 '13 at 13:33
  • How do I change that? When I run the resize command it returns that it can't run VT100 sequences. Then I tried resize -s command, which doesn't do anything but show a script to change the size by resetting $COLUMNS and $LINES. I tried the script, which also doesn't do anything.
    – Blue Ice
    Apr 3 '13 at 23:05
0

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 :-)).

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.