Previous  |  Main  |  Next
AppleScript Logo

Toggle Window Bounds

Script for: BBEdit
Copyright: Free, use at your own risk!
Description: Toggles the bounds of the frontmost window in BBEdit between full screen
and its original window bounds.

  • If you run this script on a new window which is currently in full screen mode
    this new window will get zoomed to the original window bounds of the window
    that was used with this script previously.
  • The script doesn't do advanced error checking, i.e. you might need to recompile the script:
    • if you're migrating to a higher screen resolution
    • if you've been executing this script with the BBEdit 6 about box in front
Necessary: None
Download: ToggleBounds.hqx
The Script:
property OriginalWindowBounds : {}
property FullScreenBounds : {}

	if FullScreenBounds is {} then
		tell application "Finder" to copy bounds of desktop's window to screenSize -- Remember: {left, top, right, bottom}
		set FullScreenBounds to {(item 1 of screenSize) + 2, 41, (item 3 of screenSize) - 1, (item 4 of screenSize) - 1} -- adjust to your needs
	end if
	tell application "BBEdit 6.0"
		if exists window 1 then -- only proceed if there's any open document...
			set CurrentWindowBounds to bounds of window 1
			if CurrentWindowBounds = FullScreenBounds then -- window is currently zoomed to full screen
				set bounds of window 1 to OriginalWindowBounds -- restore original window bounds
			else -- window is currently NOT zoomed to full screen
				set OriginalWindowBounds to bounds of window 1 -- save original window bounds
				set bounds of window 1 to FullScreenBounds -- zoom window to full screen
				-- since BBEdit 6 resizes any window zoomed over its own values defining "full screen"
				-- we've to re-assign the FullScreenBounds:
				set FullScreenBounds to bounds of window 1
			end if
			display dialog "No open text window!" with icon caution buttons "Oops" default button 1
		end if
	end tell
on error errMsg number errNo
	if errNo is not -128 then -- error # -128: user canceled
		set FullScreenBounds to {}
		display dialog "An error has occurred:" & return & return & ¬
			errMsg & return & "(error No: " & errNo & ")" with icon caution buttons "OK" default button 1
	end if
end try


Contact: Matthias Steffens  |  Previous  |  Main  |  Next  |  Last Updated: 26-Feb-01