Ceasar's Mind

Follow me: @Ceasar_Bautista

Posts Tagged ‘workflow

Manage your Terminal windows with your mouse

with 3 comments

I’m a Vim user, and naturally, I like to keep a lot of files open when I’m working. There are typically lots of related modules that need to be viewable at once, and the result is I need a bunch of windows open.

Such a workflow demands opening and positioning lots of terminal windows. The problem is, Cmd+N doesn’t quite cut it since it positions new terminals in an arbitrary manner.

One solution is to download something like Divvy, which creates a 6×6 grid that you assign windows to (and hotkey the assignments for speed). The problem with this is that for a big monitor, 6×6 is not granular enough and on top of that Divvy’s price is kind of hard to justify.

Fortunately, I’ve come up with a solution that, while I think there is some room for improvement, has so far turned out to be pretty good: Make the terminal window center itself on the mouse after spawning.

To do so is pretty simple if you’re willing to dig into Apple’s osascript. I can’t tell you much about it as I only read enough to get my hacks working, but here is how to set this hack up:

First you’ll need to define “/usr/bin/local/position”, a command which will position a terminal somewhere on your screen.

# Reposition the current window to (x, y) (offset from top-left corner)
osascript <<END
    # TODO: Grab the bounds of the actual window and center it properly
    tell application “Terminal” to set the position of window 1 to {$1 – 160, $2 – 100}

Next you’ll need to download MouseTools, which is a command line tool that lets you control your mouse. That should be installed in /usr/bin/local as well.

Next, we define the “/usr/bin/local/center”. It’s a one-liner: “MouseTools -location | xargs position”. MouseTools –location gives you the x and y of your cursor, and xargs just feeds it into the position command.

Finally, we need to make the center command execute every time a new terminal is created. For this, you can just go to “Preferences > Settings > Shell” and enter the command “center”.

And that’s it! Try opening a new terminal and watch it move to your mouse.

If my experience is worth anything, you’ll probably still need to do some dragging, but it’s far more manageable when terminals open up in the relative location you’re working.

And in case you were too lazy to actually do any of the above, all of the above is already packaged together on my Github.

Written by Ceasar Bautista

2012/07/17 at 22:39

Posted in Uncategorized

Tagged with