Terminal command to move terminal window?

Discussion in 'Mac Programming' started by hayduke, Aug 30, 2006.

  1. macrumors 65816

    hayduke

    Joined:
    Mar 8, 2005
    Location:
    is a state of mind.
    #1
    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?
     
  2. macrumors 68000

    Shadow

    Joined:
    Feb 17, 2006
    Location:
    Keele, United Kingdom
  3. thread starter macrumors 65816

    hayduke

    Joined:
    Mar 8, 2005
    Location:
    is a state of mind.
    #3
    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.
     
  4. Moderator emeritus

    robbieduncan

    Joined:
    Jul 24, 2002
    Location:
    London
    #4
    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...
     
  5. macrumors 68000

    savar

    Joined:
    Jun 6, 2003
    Location:
    District of Columbia
    #5
    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.
     
  6. thread starter macrumors 65816

    hayduke

    Joined:
    Mar 8, 2005
    Location:
    is a state of mind.
    #6
    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.
     
  7. Moderator emeritus

    kainjow

    Joined:
    Jun 15, 2000
    #7
    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}
     
  8. macrumors 68000

    Josh

    Joined:
    Mar 4, 2004
    Location:
    State College, PA
    #8
    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 :/
     
  9. macrumors member

    Joined:
    Aug 30, 2006
    Location:
    US
    #9
    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
    }
    
     
  10. macrumors 68000

    savar

    Joined:
    Jun 6, 2003
    Location:
    District of Columbia
    #10
    Wow! Excellent catch
     

Share This Page