Submit Hint Search The Forums LinksStatsPollsHeadlinesRSS
14,000 hints and counting!

A script to resize frontmost two windows to fill screen System
I often need to compare two windows side by side. So I wrote this AppleScript to resize the front two windows side by side, filling the screen. I have it set to run via a Quicksilver Trigger keyboard shortcut. It works in most applications.

You'll need to have "Enable access for assisstive devices" enabled under Universal Access in System Preferences for this script to work.
    •    
  • Currently 2.67 / 5
  • 1
  • 2
  • 3
  • 4
  • 5
  (6 votes cast)
 
[38,689 views]  

A script to resize frontmost two windows to fill screen | 25 comments | Create New Account
Click here to return to the 'A script to resize frontmost two windows to fill screen' hint
The following comments are owned by whoever posted them. This site is not responsible for what they say.
A script to resize frontmost two windows to fill screen
Authored by: danemcg on Jan 10, '06 07:33:16AM

Bless you! This is one basic functionality that Windoze has that Mac hasn't had that I've missed for ages. Works great.

Now, can it be generalized to tile any two (or more) windows from unrelated apps?.... (getting greedy, I know).

Thanks!



[ Reply to This | # ]
A script to resize frontmost two windows to fill screen
Authored by: galaher on Jan 10, '06 07:59:26AM

Tiger 10.4.3
Apple Error: Domain com.apple.windowserver does not exist

Searching for 'windowserver' under system wide Library as well as my user Library comes up with nothing.
Any thoughts?



[ Reply to This | # ]
A script to resize frontmost two windows to fill screen
Authored by: GlowingApple on Jan 10, '06 12:19:12PM

Is there a file in /Library/Preferences called com.apple.windowserver.plist? This is where the defaults system reads the windowserver information from. If for some reason that file isn't there (might need Developer Tools installed??? or maybe it only shows up as accessible if assistive access is enabled???) then that could be why you're getting that error.

---
Jayson --When Microsoft asks you, "Where do you want to go today?" tell them "Apple."



[ Reply to This | # ]
A script to resize frontmost two windows to fill screen
Authored by: GlowingApple on Jan 10, '06 11:48:54AM
for a "tile vertically" script, replace the "tell application frontApp" block with this:

tell application frontApp
	set var_count to number of windows as number
	set var_left to 0 as number
	repeat with x from 1 to var_count
		set bounds of window x to {var_left, menubarHeight, var_left + (screenWidth / (var_count)), screenHeight}
		set var_left to var_left + (screenWidth / (var_count))
	end repeat
end tell

---
Jayson --When Microsoft asks you, "Where do you want to go today?" tell them "Apple."

[ Reply to This | # ]

A script to resize frontmost two windows to fill screen
Authored by: GlowingApple on Jan 10, '06 11:56:21AM

This still only works on the frontmost application though, not all open windows.

---
Jayson --When Microsoft asks you, "Where do you want to go today?" tell them "Apple."



[ Reply to This | # ]
A script to resize frontmost two windows to fill screen
Authored by: GlowingApple on Jan 10, '06 01:47:51PM
I don't have access to my web server as I'm still home from school for the break (and making changes over dial-up is very slow), so I can't post the script on my site until next week, but I'll paste the code here for now. Sorry for taking up all this space on the comments page... Here is a beta version of a script that should tile visible (not hidden / closed) windows of all applications. It seems a little buggy, but so far has worked without error other than overlapping some windows by a few pixels.

on run {}
	--set screen dimension variables
	set screenWidth to word 3 of (do shell script "defaults read /Library/Preferences/com.apple.windowserver | grep -w Width") as number
	set screenHeight to word 3 of (do shell script "defaults read /Library/Preferences/com.apple.windowserver | grep -w Height") as number
	--if you plan to use this on just one computer where the screen dimensions won't change, this script will run faster if you just hard code your screen resolution with these two lines:
	--set screenWidth to 1280
	--set screenHeight to 854
	
	try
		set app_count to 0
		tell application "System Events"
			set app_count to count of (application processes whose visible is true)
		end tell
		--let's get the total number of windows visible
		set win_count to 0
		--loop through all visible applications
		repeat with y from 1 to app_count
			tell application "System Events"
				set frontApp to (name of application process y whose visible is true)
			end tell
			--loop through all windows of each application
			tell application frontApp
				set win_count to win_count + (count of (windows whose visible is true))
			end tell
		end repeat
		
		--now we need to loop through again and size and organize all the previously counted windows
		set var_left to 0
		--loop through all visible applications
		repeat with y from 1 to app_count
			tell application "System Events"
				set frontApp to (name of application process y whose visible is true)
			end tell
			--loop through all windows of each applicaiton
			set menubarHeight to check_exceptions(frontApp)
			tell application frontApp
				repeat with x from 1 to count of (windows whose visible is true)
					set bounds of window x to {var_left, menubarHeight, var_left + (screenWidth / (win_count)), screenHeight}
					set var_left to var_left + (screenWidth / (win_count))
				end repeat
			end tell
		end repeat
	on error the error_message number the error_number
		display dialog "Error: " & the error_number & ". " & the error_message buttons {"OK"} default button 1
	end try
end run

on check_exceptions(frontApp)
	set menubarHeight to 22
	--some apps are wacky and put the windows higher for some reason, adjust for this bug.
	if (frontApp is equal to "Finder" or frontApp is equal to "Microsoft Entourage") then
		set menubarHeight to 44
	end if
	--leave room for the Excel Toolbar
	if (frontApp is equal to "Microsoft Excel") then
		set menubarHeight to 55
	end if
	return menubarHeight
end check_exceptions
If you find any bugs, let me know.

---
Jayson --When Microsoft asks you, "Where do you want to go today?" tell them "Apple."

[ Reply to This | # ]

A script to resize frontmost two windows to fill screen
Authored by: hughescr on Jan 10, '06 04:56:59PM
I've done a version of the script which will work for any number of windows, ignores invisible windows and windows with no title (adium seems to have a title-less window which one can't see though it's marked as "visible"). You can specify your preference for number of columns (which defaults to 2). If you run it and there's only one window, it'll just make that one window will the screen. Script source is here

[ Reply to This | # ]
A script to resize frontmost two windows to fill screen
Authored by: SimonDorfman.com on Jan 14, '06 10:09:26PM
Cool script. One thing wasn't working for me though:
set numRows to round (ceil(windowCount / numCols))
Maybe ceil was a type-o? After some messing around, I figured out it should be changed to this:
set numRows to round (windowCount / numCols) rounding up
I also added a special case if the number of windows is less than the number of columns preference. So here's the complete script with those changes:

--Run via quicksilver trigger to tile all windows

--found in comments here: http://www.macosxhints.com/article.php?story=20060105082728937

property numCols : 2
property screenWidth : 1280
property screenHeight : 854
-- If you don't want to hard-code your screen width, because eg. you use multiple screens with differing properties at different times, then uncomment the 2 lines below:
--set screenWidth to word 3 of (do shell script "defaults read /Library/Preferences/com.apple.windowserver | grep -w Width") as number
--set screenHeight to word 3 of (do shell script "defaults read /Library/Preferences/com.apple.windowserver | grep -w Height") as number

set menubarHeight to 22

tell application "System Events"
	set frontApp to name of first application process whose frontmost is true
end tell

--some apps are wacky and put the windows higher for some reason, adjust for this bug.
if (frontApp is equal to "Finder" or frontApp is equal to "Microsoft Entourage") then
	set menubarHeight to 44
end if
--leave room for the Excel Toolbar
if (frontApp is equal to "Microsoft Excel") then
	set menubarHeight to 55
end if

try
	tell application frontApp
		-- Ignore windows that are invisible or that don't have a title
		set windowCount to count of (windows whose visible is true and name is not "")
		set allWindowCount to count of windows
		
		-- Set number of rows appropriately
		set numRows to round (windowCount / numCols) rounding up
		
		-- Special case if the number of windows is less than the number of columns preference
		if windowCount is less than or equal to numCols then
			set numRows to 1
			set numCols to windowCount
		end if
		
		-- Special case is there's only one window
		if windowCount = 1 then
			set numRows to 1
			set numCols to 1
		end if
		
		-- skipWindow is for skipping over windows which are invisible or titleless
		set skipWindow to 0
		repeat with j from 0 to numRows - 1
			repeat with i from 0 to numCols - 1
				-- If we've done all the windows, then just get out
				if (j * numCols + i + 1) > windowCount then
					exit repeat
				end if
				-- Get a handle to the window we might want to resize
				set theWindow to window (j * numCols + i + 1 + skipWindow)
				-- Check that the window is visible and titled -- if it's not, then skip it
				repeat while (visible of theWindow is false or name of theWindow is "")
					set skipWindow to skipWindow + 1
					set theWindow to window (j * numRows + i + 1 + skipWindow)
				end repeat
				
				-- resize the window
				set bounds of theWindow to {¨
					round (i * screenWidth / numCols), ¨
					menubarHeight + (round (j * (screenHeight - menubarHeight) / numRows)), ¨
					round ((i * screenWidth / numCols) + (screenWidth / numCols)), ¨
					round ((menubarHeight + (round (j * (screenHeight - menubarHeight) / numRows))) + (screenHeight - menubarHeight) / numRows) ¨
						}
			end repeat
		end repeat
	end tell
on error the error_message number the error_number
	display dialog "Error: " & the error_number & ". " & the error_message buttons {"OK"} default button 1
end try


[ Reply to This | # ]
ignore minimized windows and fix the resizing of windows in Finder
Authored by: SimonDorfman.com on Jan 15, '06 01:31:53AM
I further hacked this script to ignore minimized windows and fix the resizing of windows in Finder due to the weird menubarHeight 44 instead of 22 bug. Here's the updated script:

--Run via quicksilver trigger to tile all windows

--found in comments here: http://www.macosxhints.com/article.php?story=20060105082728937

property numCols : 2
property screenWidth : 1280
property screenHeight : 854
-- If you don't want to hard-code your screen width, because eg. you use multiple screens with differing properties at different times, then uncomment the 2 lines below:
--set screenWidth to word 3 of (do shell script "defaults read /Library/Preferences/com.apple.windowserver | grep -w Width") as number
--set screenHeight to word 3 of (do shell script "defaults read /Library/Preferences/com.apple.windowserver | grep -w Height") as number

set menubarHeight to 22

tell application "System Events"
	set frontApp to name of first application process whose frontmost is true
end tell

--some apps are wacky and put the windows higher for some reason, adjust for this bug.
if (frontApp is equal to "Finder" or frontApp is equal to "Microsoft Entourage") then
	set menubarHeight to 44
end if
--leave room for the Excel Toolbar
if (frontApp is equal to "Microsoft Excel") then
	set menubarHeight to 55
end if

try
	-- For some reason Finder calls minimized windows "collapsed" while other apps call them "miniaturized", so I deal with this by duplacating lots of code and having this big if/else. It's okay though because Finder's menubarHeight of 44 bug requires some tweaking of the numbers to resize the windows right. So the duplicate code isn't a total waste, but I'm sure there's a way to do this with list repeating.
	if frontApp is "Finder" then
		tell application "Finder"
			-- Ignore windows that are minimized, invisible or that don't have a title
			set windowCount to count of (windows whose visible is true and name is not "" and collapsed is false)
			set allWindowCount to count of windows
			
			-- Set number of rows appropriately
			set numRows to round (windowCount / numCols) rounding up
			
			-- Special case if the number of windows is less than the number of columns preference
			if windowCount is less than or equal to numCols then
				set numRows to 1
				set numCols to windowCount
			end if
			
			-- Special case is there's only one window
			if windowCount = 1 then
				set numRows to 1
				set numCols to 1
			end if
			
			-- skipWindow is for skipping over windows which are invisible or titleless
			set skipWindow to 0
			repeat with j from 0 to numRows - 1
				repeat with i from 0 to numCols - 1
					-- If we've done all the windows, then just get out
					if (j * numCols + i + 1) > windowCount then
						exit repeat
					end if
					-- Get a handle to the window we might want to resize
					set theWindow to window (j * numCols + i + 1 + skipWindow)
					-- Check that the window is visible and titled -- if it's not, then skip it
					repeat while (visible of theWindow is false or name of theWindow is "")
						set skipWindow to skipWindow + 1
						set theWindow to window (j * numRows + i + 1 + skipWindow)
					end repeat
					
					-- resize the window
					set bounds of theWindow to {¨
						round (i * screenWidth / numCols), ¨
						menubarHeight + (round (j * (screenHeight - 22) / numRows)), ¨
						round ((i * screenWidth / numCols) + (screenWidth / numCols)), ¨
						round ((22 + (round (j * (screenHeight - 22) / numRows))) + (screenHeight - 22) / numRows) ¨
							}
				end repeat
			end repeat
		end tell
	else
		tell application frontApp
			-- Ignore windows that are minimized, invisible or that don't have a title
			set windowCount to count of (windows whose visible is true and name is not "" and miniaturized is false)
			set allWindowCount to count of windows
			
			-- Set number of rows appropriately
			set numRows to round (windowCount / numCols) rounding up
			
			-- Special case if the number of windows is less than the number of columns preference
			if windowCount is less than or equal to numCols then
				set numRows to 1
				set numCols to windowCount
			end if
			
			-- Special case is there's only one window
			if windowCount = 1 then
				set numRows to 1
				set numCols to 1
			end if
			
			-- skipWindow is for skipping over windows which are invisible or titleless
			set skipWindow to 0
			repeat with j from 0 to numRows - 1
				repeat with i from 0 to numCols - 1
					-- If we've done all the windows, then just get out
					if (j * numCols + i + 1) > windowCount then
						exit repeat
					end if
					-- Get a handle to the window we might want to resize
					set theWindow to window (j * numCols + i + 1 + skipWindow)
					-- Check that the window is visible and titled -- if it's not, then skip it
					repeat while (visible of theWindow is false or name of theWindow is "")
						set skipWindow to skipWindow + 1
						set theWindow to window (j * numRows + i + 1 + skipWindow)
					end repeat
					
					-- resize the window
					set bounds of theWindow to {¨
						round (i * screenWidth / numCols), ¨
						menubarHeight + (round (j * (screenHeight - menubarHeight) / numRows)), ¨
						round ((i * screenWidth / numCols) + (screenWidth / numCols)), ¨
						round ((menubarHeight + (round (j * (screenHeight - menubarHeight) / numRows))) + (screenHeight - menubarHeight) / numRows) ¨
							}
				end repeat
			end repeat
		end tell
	end if
on error the error_message number the error_number
	display dialog "Error: " & the error_number & ". " & the error_message buttons {"OK"} default button 1
end try


[ Reply to This | # ]
ignore minimized windows and fix the resizing of windows in Finder
Authored by: ebeffel on Feb 04, '06 03:04:13PM

I dont have a /Library/Preferences/com.apple.windowserver file on my machine. What do I do to create one? Are you aware of alternative ways to get the size of the displays? Do they work with two displays?

Thanks, Ernie



[ Reply to This | # ]
A script to resize frontmost two windows to fill screen
Authored by: winklebleck on Jan 10, '06 09:07:16AM

Sorry, I'm new to quicksilver, Now where do i put this and how do i use it?



[ Reply to This | # ]
A script to resize frontmost two windows to fill screen
Authored by: GlowingApple on Jan 10, '06 01:52:15PM

Go to the Preferences in Quicksilver. Click on Triggers in the left pane (I think this is built-in to the newest Quicksilver by default, but it may have been added by a plugin). Click the plus to add a trigger. Select the script in the Command section. Select a key combination in the Trigger section. Make sure the trigger is checked and close the Preferences window. The trigger should activate immediately.

---
Jayson --When Microsoft asks you, "Where do you want to go today?" tell them "Apple."



[ Reply to This | # ]
A script to resize frontmost two windows to fill screen
Authored by: GlowingApple on Jan 10, '06 11:31:36AM

I have been wanting to write a script like this for some time, but never knew where to find the window widths and heights other than manually. Thanks!

Now to make a fill screen script that will fit the window to the entire screen, sort of like the Windows style maximize.

---
Jayson --When Microsoft asks you, "Where do you want to go today?" tell them "Apple."



[ Reply to This | # ]
A script to resize frontmost two windows to fill screen
Authored by: GlowingApple on Jan 10, '06 11:35:55AM
Just in case anyone is interested, to make this a fill window script, just change the lines that read:
		set bounds of window 1 to {0, menubarHeight, (screenWidth / 2), screenHeight}
		set bounds of window 2 to {(screenWidth / 2), menubarHeight, screenWidth, screenHeight}
by deleting the second line and changing the first line to:
		set bounds of window 1 to {0, menubarHeight, screenWidth, screenHeight}

---
Jayson --When Microsoft asks you, "Where do you want to go today?" tell them "Apple."

[ Reply to This | # ]

A script to resize frontmost two windows to fill screen
Authored by: ajMac on Jan 10, '06 01:08:42PM

Can I use this script by saving it as an application in the script editor and then executing it?
I tried it, but I am getting this error:
Error: -1700. System Events got an error: Can't make the bounds of window 1 into type reference.

I also tried executing the script from the shell script menu. Same error.
I am new to apple scripts, so could be making an obvious mistake, would like to learn.

p.s: The script works in the script editor.

---
-AJ



[ Reply to This | # ]
A script to resize frontmost two windows to fill screen
Authored by: GlowingApple on Jan 10, '06 01:43:55PM

The script cycles through the current running application. If you run a script with Quicksilver, it does not open a new application but keeps the focus with whatever application you have at the front when you run the script. If you make a new application and run it, that application grabs the focus and becomes the front most application, the it then tries to resize itself and probably runs into issues as it has no visible window.

I don't think I'm advanced enough with Mac and Applescript to get this to work with a separate application. The script would have to capture the application that was front most before the script ran. I'm not sure if this is recorded anywhere in the OS though.

---
Jayson --When Microsoft asks you, "Where do you want to go today?" tell them "Apple."



[ Reply to This | # ]
A script to resize frontmost two windows to fill screen
Authored by: ChaChi on Jan 10, '06 01:00:28PM
FYI:

There is absolutely NO reason why "Enable access for assisstive devices" needs to be enabled in order to use this script. That only needs to be enabled for UI scripting which this script does not do.

[ Reply to This | # ]
A script to resize frontmost two windows to fill screen
Authored by: encro on Jan 13, '06 09:57:04AM

What about using Exposť for this at application level (F9 by default) or isn't this an option due to limited interactivity? Still I would think this would be good enough for a side by side comparison.



[ Reply to This | # ]
A script to resize frontmost two windows to fill screen
Authored by: dkulp on Jan 25, '06 07:38:44AM
For what it's worth, all of the scripts in this thread try to determine the screen size by scanning through the com.apple.windowserver plist. Unfortunately, this just doesn't work if you have multiple DisplaySets. For example, on my laptop:
% defaults read /Library/Preferences/com.apple.windowserver | grep -w Width
                Width = 800; 
                Width = 1024; 
                Width = 1024; 
                Width = 1024; 
                Width = 1024; 
                Width = 1920; 
                Width = 1024; 
                Width = 800; 
                Width = 800; 
                Width = 1680; 
                Width = 1024; 
                Width = 1024; 
                Width = 1024; 
                Width = 800; 
                Width = 1024; 
                Width = 1024; 
                Width = 1024; 
                Width = 1680; 
                Width = 800; 
                Width = 800; 
                Width = 800; 
                Width = 800; 
                Width = 1680; 
                Width = 1024; 
                Width = 1680; 
                Width = 1024; 
                Width = 800; 
                Width = 800; 
                Width = 1680; 
                Width = 1024; 
                Width = 1680; 
                Width = 1024; 
                Width = 1680; 
                Width = 1024; 
                Width = 1680; 
                Width = 800; 
                Width = 800; 
MacOS apparently remembers every display that you've used (and you can see that I have used many).

What we want is to find the current display dimensions, but that's not indicated in this plist. I found a post elsewhere that asked Safari to run a JavaScript that returns screen.availHeight and screen.availWidth. Extra Suites provides an AppleScript extension with screen dimension information.

I don't know a general, free solution to get the screen dimensions.

[ Reply to This | # ]

A script to resize frontmost two windows to fill screen
Authored by: craigw on Jan 23, '07 04:57:38PM

here's what I put in for getting the desktop size:
set screenWidth to (do shell script "system_profiler SPDisplaysDataType | grep Resolution | awk '{print $2}'")
set screenHeight to (do shell script "system_profiler SPDisplaysDataType | grep Resolution | awk '{print $4}'")



[ Reply to This | # ]
A script to resize frontmost two windows to fill screen
Authored by: Clark_Kent on Nov 25, '07 01:31:41PM

Here's a link to some great window maneuvering apple scripts:

http://jon.smajda.com/blog/?p=609



[ Reply to This | # ]
A script to resize frontmost two windows to fill screen
Authored by: Clark_Kent on Nov 25, '07 01:33:26PM

Here's a link to some gerat window manipulation scripts:

(You'll need to change the screen size in the script editor)


http://jon.smajda.com/blog/?p=609



[ Reply to This | # ]
A script to resize frontmost two windows to fill screen
Authored by: Jekel on Apr 25, '10 02:03:19AM

Any Possibility to get Entourage to work with this or especially Microsoft Word?
Also, I know this is probably a huge stretch, but what about windows inside of windows, such as in excel documents.

Helpful steps that I had to figure out as a first time user:
Open AppleScript Editor in the Utilities folder in the Applications folder.
Copy paste the above quoted code and save it as what ever you want and put it where ever you want it, just remember where.
Open Quick silver, and navigate to the triggers pane - On version B58 (i don't know what that means) but it's the newest one as of apr 25 2010, there is an arrow top right of the window that opens up if you run the quick silver application. -> Select Triggers.
Click the + in the Bottom Left corner. Select HotKeys.
Drag the script file you saved from eariler into the top box directly under the text "Select an Item"
Then hit save.
Highlight the newly created command, and press the i in the bottom right corner of the box, and then create a hotkey that does not conflict with the current default hotkeys (such as cmd c for copy).
Finally (if your script and hotkey combo aren't working) Go back to the arrow where you originally selected triggers, and select Quick Application, then restart quick silver, and your command should work!
If this doesn't work, make sure the script is correct in the first place. You can open through recent documents in apple script editor, make changes, and compile, then save, and your hot key does not need to be changed or anything.

(I May be writing this for no one now, But hopefully someone finds this helpful!) ... (took me until 5 am to figure all this stuff out on my own! Probably my own fault though, cause after i hit post, i'll probably notice there was a perfect step by step guide i just decided to gloss over.)

Hopes this helps anyways!



[ Reply to This | # ]
A script to resize frontmost two windows to fill screen
Authored by: Jekel on Apr 25, '10 02:05:17AM

Also if you simply go to the Apple in the top left and select about this mac and then get more info. Then from the left hand bar select Graphics/Displays, you can find out what your resolution is exactly.
Alternatively you could get to this same place by typing 'system profiler' into spotlight.



[ Reply to This | # ]
A script to resize frontmost two windows to fill screen
Authored by: rudi.kami on Apr 26, '10 05:23:04PM

Hello,
I get the last script that you posted to work very well with Safari, Finder and other apps, but not with MS Word, which is the one I really needed this script for. I get the following error message: Error: -1700. Can't make missing value into type real.
The previous scripts on this page work with MS word (get no error) but do not fill the screen entirely, so I would need to manually drag the 2 windows to fill the screen (50/50) which would make the script useless.
I know this post is old, but maybe someone can answer.
Thanks!
Rudi



[ Reply to This | # ]