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