Pick of the Week - Nov 10 [Show all picks]
Path Finder 5 - A feature-laden Finder replacement
Submit Hint Search The Forums LinksStatsPollsFAQHeadlinesRSS
12,000 hints and counting!

Move and resize app windows via AppleScript System
I'm a neatness freak, and I hate lots of messy overlapping windows everywhere. But I'm also a keyboard junkie, and I hate using the trackpad a lot. And I don't want anymore background processes hogging memory, or more applications to open for such a simple task -- so what to do? Answer: AppleScript. I wrote a collection of AppleScripts that use System Events to control the window size and position of the frontmost application. Also, the window snaps to a grid to make it easy to place next to other windows without overlapping.

You can find the scripts on my iDisk public folder (Go » iDisk » Other User's Public Folder, then enter phildooher). Download the zip file and put the (nine) scripts in your usual script folder. The scripts are known to work on OS X 10.4.11, but are untested on 10.5. [robg adds: I tested a few of these, but not all, on 10.5, and they seem to work as described.]

Assign keyboard shortcuts to these scripts (using Quicksilver or your other favorite tool), and you can move and resize many application windows without using the mouse. Also, there is a 'Finder window 1 remember position' script to stop those pesky Finder windows wandering about after closing. These scripts work in many apps, including at least these: Finder, Safari, Mail, Firefox, TextEdit, Script Editor, Preview, OpenOffice Aqua, Skype, and many others. They don'e seem to work in iTunes, NeoOffice (window 1 resizes, but no scroll bars), and Word 2004. Apps that require specific window sizes, or have floating windows, can be uncooperative. QuickTime Player usually resizes windows proportionally, so video playback might fit to the window instead of being the correct aspect ratio. There is more info on how the scripts work inside the scripts (especially the 'Frontmost application window snap to grid move left' script).

I have a 13" MacBook, so the screen size for the scripts is set to 1280x800 (my Dock is on the right, hidden.) Change the _screenHeight and _screenWidth variables if your size is different (or if you don't want windows behind the Dock). The grid size I have chosen is 64 horizontally and 50 vertically (64 fits into 1280 twenty times, and 50 fits into 800 sixteen times.) Change the variable _gridSize if you prefer a different grid (ie minimum movement size).

The scripts cause the window to snap to a grid before actually being moved. Therefore, some windows will move slightly the opposite way than intended at first. The 'Finder window 1 remember position' script works by turning the window toolbar off and on. You can also stick the window by clicking on the toolbar with the mouse (but hey -- that's cheating). I use keyboard shortcuts that are (for me) easy to remember:
  • Move window left: ⌘⌥⇧←
  • Move window right: ⌘⌥⇧→
  • Move window up: ⌘⌥⇧↑
  • Move window down: ⌘⌥⇧↓
  • Reduce window size horizontally: ⌘⌥⇧⌃←
  • Increase window size horizontally: ⌘⌥⇧⌃→
  • Reduce window size vertically: ⌘⌥⇧⌃↑
  • Increase window size vertically: ⌘⌥⇧⌃↓
  • Remember Finder window 1 position - ⌘⌥⇧enter
Check your apps to make sure these shortcuts don't conflict with any that are already assigned -- I noticed some funny behaviour in NeoOffice, for instance. The window size is limited to the screen size. The window can be moved off the sides of the screen, but it can't disappear completely.

Quicksilver fans: You can move the window whilst the Quicksilver interface is open -- this is useful for dropping folders into open/save dialogs, etc.

That's it -- any constructive criticism on how the scripts are written and documented, or on how to make this idea better would be greatly appreciated. (Maybe an AppleScript application that opens on start-up and picks up the keystrokes? This would avoid Quicksilver being required for the shortcuts.)

[robg adds: I have mirrored the AppleScripts here on macosxhints.com, just in case the .Mac source ever goes away.]
    •    
  • Currently 0.00 / 5
  • 1
  • 2
  • 3
  • 4
  • 5
  (0 votes cast)
 
[16,130 views]  

Move and resize app windows via AppleScript | 6 comments | Create New Account
Click here to return to the 'Move and resize app windows via AppleScript' hint
The following comments are owned by whomever posted them. This site is not responsible for what they say.
Move and resize app windows via AppleScript
Authored by: PhilHints on Wed, May 28 2008 at 8:32PM PDT
Sorry, my keyboard shortcuts didn't show - the move window scripts use:
command, option, shift and the cursors.

The resize scripts use:
command, option, shift, control and the cursors.

The 'Remember Finder window position' script uses:
command, option, shift and enter.

PhilHints

[ Reply to This | # ]
Move and resize app windows via AppleScript
Authored by: taozhyn on Fri, May 30 2008 at 11:55PM PDT
I was having problems with running the scripts, until I found some similar scripts (spooky).
In their setup script they test if "access for assistive devices" is enabled in Universal Access.

Once I enabled this your scripts started to work.

Thanks.

[ Reply to This | # ]
Move and resize app windows via AppleScript
Authored by: PhilHints on Sat, May 31 2008 at 4:27AM PDT
You're right - I turned off 'Enable access for assistive devices' and the scripts stopped working. Anybody know why?

The reasons I wrote these scripts are because: I couldn't find anything similar; I thought someone might find them useful; It's great to get input on how to make scripts better. If you've found something better (i.e. a script that checks for assistive devices) the can you please post a link so I can see for myself. (Also I love ghost stories...)




[ Reply to This | # ]
Move and resize app windows via AppleScript
Authored by: matters on Sun, Jun 1 2008 at 6:55AM PDT
Those scripts are cool and all, but I think you'll find that this app, although requiring the mouse/trackpad, will give you a much more elegant and innovative way of controlling window positions and sizes. I've found now that I can't live without it. :)

Zooom/2
http://coderage-software.com/zooom/

[ Reply to This | # ]
Closest thing to UltraMon or MultiMon
Authored by: gabrielradic on Tue, Apr 14 2009 at 8:05AM PDT
These are awesome! I simplified them to only move stuff from a screen to another. I also removed the checks for the screen edges, and let Mac OS take care of that: Aqua won't let windows move out of the screen entirely.

Also, I prefer Butler for my shortcuts and AppleScript, among other stuff good too.

[ Reply to This | # ]
Move and resize app windows via AppleScript
Authored by: fruityth1ng on Thu, Apr 30 2009 at 6:16AM PDT
PhilHints, thanks a bundle for this! -and RobG, seriously, thanks for the mirror - the .mac source was indeed gone :)

[ Reply to This | # ]