# Get topmost app
tell application "System Events" to set frntProc to name of every process whose frontmost is true and visible is true
tell application named (item 1 of frntProc) to set currBounds to the bounds of the front window
# Get desktop bounds
tell application "Finder" to set desk to the bounds of the window of the desktop
tell application "Terminal"
activate (do script with command "")
set newBounds to the bounds of the front window
# Get the distances we're working with
set onLeft to (item 1 of currBounds)
set onTop to (item 2 of currBounds)
set onRight to ((item 3 of desk) - (item 3 of currBounds))
set onBottom to ((item 4 of desk) - (item 4 of currBounds))
set newW to ((item 3 of newBounds) - (item 1 of newBounds))
set newH to ((item 4 of newBounds) - (item 2 of newBounds))
if (onRight > newW) then
set the bounds of the front window to {item 3 of currBounds, (item 2 of currBounds) + newH, (item 3 of currBounds) + newW, (item 2 of currBounds) + newH * 2}
else if (onBottom > newH) then
set the bounds of the front window to {item 1 of currBounds, (item 4 of currBounds) + newH, (item 1 of currBounds) + newW, (item 4 of currBounds) + newH * 2}
else if (onLeft > newW) then
set the bounds of the front window to {(item 1 of currBounds) - newW, (item 2 of currBounds) + newH, item 1 of currBounds, (item 2 of currBounds) + newH * 2}
else if (onTop > newH) then
set the bounds of the front window to {item 1 of currBounds, item 2 of currBounds, (item 1 of currBounds) + newW, (item 2 of currBounds) + newH}
end if
end tell
Sunday, April 26, 2009
"Friendly" terminal placement with applescript
A lot of my work flow involves opening new terminals. Unfortunately, OS X almost always puts its new terminals right on top of its old ones, which is not terribly useful to me. With a bit of Applescript (launched by Spark), I make them launch to the side of the current (active) window. It's a good start, at least.
Subscribe to:
Post Comments (Atom)
No comments:
Post a Comment