Mac Terminal command to move terminal window?

hayduke

macrumors 65816
Original poster
Mar 8, 2005
1,177
2
is a state of mind.
I'm a *bit* type-A about the location of my terminal windows. When I toggle between mirrored and dual display mode the terminal windows get bumped around (really annoying!) and I'd like to simple way to put them back where they belong. I have an alias that can resize the window (resize -s 24 80), but I can't figure out how to change the position. Thoughts?
 

hayduke

macrumors 65816
Original poster
Mar 8, 2005
1,177
2
is a state of mind.
Sorry, you missed the part about me being type-A. :eek:

I can drag them, but I swap between mirrored and dual display frequently and its just kind of a pain to drag all five terminals back to their neat little homes.

I can resize them easily enough from the terminal and I bet some Unixy-savvy reader will have a suggestion for the pains that ail me.
 

robbieduncan

Moderator emeritus
Jul 24, 2002
24,638
61
Harrogate
I'm fairly sure you can move a window (and resize it) from AppleScript. You could easily write a script that moves and resizes all your Terminal windows to where you want them...
 

savar

macrumors 68000
Jun 6, 2003
1,952
0
District of Columbia
hayduke said:
Sorry, you missed the part about me being type-A. :eek:

I can drag them, but I swap between mirrored and dual display frequently and its just kind of a pain to drag all five terminals back to their neat little homes.

I can resize them easily enough from the terminal and I bet some Unixy-savvy reader will have a suggestion for the pains that ail me.
With an XTerm I'll bet this is possible...but for Terminal.app? I doubt it.

I agree with the other poster. If positioning is important, write an AppleScript. You can always execute this script from the command line, if that's what you're concerned about.
 

hayduke

macrumors 65816
Original poster
Mar 8, 2005
1,177
2
is a state of mind.
So here is an Applescript hack that works okay:

tell application "Terminal"
activate
set bounds of window 1 to {0, 0, 505, 320}
set bounds of window 2 to {0, 338, 505, 338 + 320}
set bounds of window 3 to {505, 0, 505 + 505, 320}
set bounds of window 4 to {505, 338, 505 + 505, 338 + 320}
set bounds of window 5 to {0, 338 + 338 - 20, 1010, 338 + 338 + 150}
end tell

The only trouble is that it will rearrange the windows because "window 1" is the most recently active window. Not sure if there is a way to do it based upon the window title, each of which contains "open apple"-# (eg open-apple 1 for the "first" window).

This works for now, but if there are other solutions, I'd be curious to hear them.
 

kainjow

Moderator emeritus
Jun 15, 2000
7,958
3
I find it extremely annoying how all the windows get moved around when I switch from my 23" ACD to my MacBook's display. I just bought the ACD a few weeks ago and since it's summer I haven't had a need to take my MacBook around, but once school starts back up this Fall I'll be using it a lot and having to reposition all my windows every time will be very annoying. I wish there was a "global" solution to this but I don't think there is.

But on the topic of AppleScript.. you can assign names to your Terminal windows via Terminal (menu bar) > Window Settings, then choose Window from the popup button. Then you can refer to them in AppleScript like this:
Code:
set bounds of first window whose name starts with "blah" to {0, 0, 200, 200}
 

Josh

macrumors 68000
Mar 4, 2004
1,640
1
State College, PA
If you were running X11 and eTerm, it is pretty simple and can be done via command.

You can also change their size, whether they have borders and control buttons, and their transparency from the command line.

But, that requires using a different terminal application :/
 

tedsmith3rd

macrumors member
Aug 30, 2006
54
0
US
Terminal.app can do it too...

If you'd prefer to use the command line directly, Terminal.app can use xterm escape sequences too. I knocked a shell function out for your use with both moving and resizing Terminal windows. Add the code below to your .bash_profile or .profile. From then on in new terminal windows, you can type:

bumpNjump -x 10 -y 20 -w 800 -h 300

x and y are coordinates for the window;
w and h are width and height in pixels

The example above moves the window to 10,20 and sets the width to 800 and the height to 300. You don't have to set both the size and the position at the same time if you don't want to.

BTW, Bump 'n' Jump: greatest game ever.

Code:
function bumpNjump()
{
   local xDimension="" yDimension="" width="" height="" OPTIND

   while getopts 'x:y:w:h:' thisArg; do
      case "${thisArg}" in
         x) xDimension="${OPTARG}" ;;
         y) yDimension="${OPTARG}" ;;
         w) width="${OPTARG}" ;;
         h) height="${OPTARG}" ;;
      esac
   done

   if [ -n "${width}" -a -n "${height}" ]; then
      echo -en '\E[4;'${height}';'${width}'t';
   fi

   if [ -n "${xDimension}" -a -n "${yDimension}" ]; then
      echo -en '\E[3;'${xDimension}';'${yDimension}'t'
   fi
}
 

savar

macrumors 68000
Jun 6, 2003
1,952
0
District of Columbia
tedsmith3rd said:
If you'd prefer to use the command line directly, Terminal.app can use xterm escape sequences too. I knocked a shell function out for your use with both moving and resizing Terminal windows. Add the code below to your .bash_profile or .profile. From then on in new terminal windows, you can type:
Wow! Excellent catch