Showing posts with label window. Show all posts
Showing posts with label window. Show all posts

Wednesday, November 21, 2007

Tile OS X Terminal window to Finder with AppleScript

I updated my AppleScript that will tile the terminal window nicely below the frontmost finder window.

For some reason setting the Terminal window bounds is very buggy. I resorted to using the deprecated methods {position and size} and have to loop it three times to ensure that it positions correctly.

I tied this to command-; in my app launcher, QuickSilver



tell application "Finder"
--make new Finder window
activate
if not (exists window index 1) then
make new Finder window
end if
set {x1, y1, x2, y2} to bounds of window index 1
end tell

tell application "Terminal"
activate

if (count of windows) is 0 then
tell application "Terminal" to activate
tell application "System Events" to tell process "Terminal" to keystroke "t" using command down
end if

-- For some reason it can take up to 3 times for Terminal to be properly adjusted
set L to {1, 2, 3}
repeat with xxx in L
set {xx1, yy1, xx2, yy2} to bounds of window index 1
set position of window index 1 to {x1, y1 + {yy2 - yy1}}
set size of window index 1 to {x2 - x1, y2 - y1}
end repeat

end tell

Sunday, August 26, 2007

OS X Finder iTerm applescript window tiling

If you are an OS X developer no doubt you use iTerm. If you haven't set up your unix environment to synchronize between Finder and OS X you should. There are a number of examples but here is the ones I used since I'm a zsh fan:

iTerm Terminal Customization

Now the other thing I wanted was to have a quick-key combination to display both the front finder and iTerm windows and position them nicely tiled. This way I could work in an IDE but have my bare-bones development windows appear in a snap. Here is my applescript code:


tell application "Finder"
--make new Finder window
activate
if not (exists window index 1) then
make new Finder window
end if
set {x1, y1, x2, y2} to bounds of window index 1
end tell

tell application "iTerm"
activate
if not (exists window index 1) then
set myterm to (make new terminal)
tell myterm
launch session "Default Session"
end tell
end if

set {xx1, yy1, xx2, yy2} to bounds of window index 1
set bounds of window index 1 to {x1, y2, x2, y2 + (yy2 - yy1)}
activate
end tell


Store the script in your home/Library/Scripts folder and from there you can assign a hot-key.

Why don't I just use PathFinder? Well I own it and used it quite a bit but there are things that just make me angry about it that hopefully they'll fix.


1. It is a resource hog
2. It doesn't allow me to simply type a path into an input box (actually almost all OS X Finder clones have this issue). OS X developers seem to like the mouse and drilling down.
3. The UI can be quite busy and some things that should be simple (finding files in the current directory or below for example are a pain in the butt.


Anyway, now that I'm doing quite a bit of development on my mac I'm using QuickSilver, Finder, and iTerm with applescript to glue them together. Simple.

What inspired me to dump PathFinder? This great podcast that showed how much hidden value is in the limited basic Finder application and how a little knowledge can make it much better suited to your workflow.

Living with the Finder