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


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 | # ]