View Single Post
An applescript for OS X 10.7 – toggles in and out of full-screen view, using a narrowed editing window in full-screen view, with dark linen background to left and right.

Code:
property pTitle : "Narrow 10.7 full screen mode for 003 - Toggle in and out"
property pVer : "0.01"

-- TOGGLES IN AND OUT OF oo3 FULL-SCREEN MODE
-- IN FULL-SCREEN MODE, NARROWS THE EDITING WINDOW, LEAVING A DARK LINEN BACKGROUND TO LEFT AND RIGHT

-- How wide a proportion of your screen should the 003 editing window be ? (adjust for comfort  :-)
property prWidthPropn : 0.4

-- Only suitable for single screen setups
-- For dual screen setups, see the Keyboard Maestro macros at:
-- http://web.me.com/robinfrancistrew/Site/RESIZE_OS_X_WINDOWS_some_Keyboard_Maestro_macros.html

tell application id "OOut"
	if (count of documents) < 1 then return
end tell

tell application "Finder"
	set blnPreLion to (version < "10.7")
	set {rX, rY, rX1, rY1} to (get bounds of window of desktop)
	set {rWidth, rHeight} to {rX1 - rX, rY1 - rY}
end tell
set blnGUIEnabled to GUIEnabled()
set blnFullScreen to isfullscreen("OOut")

tell application id "OOut"
	-- WHICH WINDOW ARE WE RESIZING ?
	if blnFullScreen then
		set oWin to window 2
	else
		if blnPreLion then
			set oWin to window 1
		else
			if not blnGUIEnabled then return
			set mnuFullScreen to my GetMenuItem("OOut", {"View", "Enter Full Screen"})
			activate
			tell application id "sevs" to click mnuFullScreen
			set blnFull to false
			repeat while not blnFull
				set blnFull to my isfullscreen("OOut")
			end repeat
			set oWin to window 2
		end if
	end if
	
	-- CENTRE THE WINDOW (FULL HEIGHT) AND RESIZE ITS WIDTH AS A PROPORTION OF THE SCREEN
	set rNewWidth to prWidthPropn * rWidth
	set rLeft to rX + ((rWidth - rNewWidth) / 2)
	set lstBounds to {rLeft, rY, rLeft + rNewWidth, rHeight}
	
	if bounds of oWin ≠ lstBounds then
		set bounds of oWin to lstBounds
	else
		if blnFullScreen then
			if (not blnPreLion) and blnGUIEnabled then
				set mnuFullScreen to my GetMenuItem("OOut", {"View", "Exit Full Screen"})
				activate
				tell application id "sevs" to click mnuFullScreen
			end if
		end if
	end if
end tell

on isfullscreen(strAppID)
	tell application "Finder" to set blnPreLion to (version < "10.7")
	if blnPreLion then
		return false
	else
		tell application id "sevs"
			set lstApps to application processes where creator type = strAppID
			if length of lstApps < 1 then return false
			set lstWins to windows of first item of lstApps
			if length of lstWins < 1 then return false
			return value of (attribute "AXFullScreen" of item 1 of lstWins)
		end tell
	end if
end isfullscreen

-- RETURNS A REFERENCE TO A CLICKABLE MENU ITEM
-- E.G. set mnuZoomFit to GetMenuItem("OGfl", {"View", "Zoom", "Zoom to Selection"})
on GetMenuItem(strAppCode, lstMenu)
	set lngChain to length of lstMenu
	if lngChain < 2 then return missing value
	
	tell application id "sevs"
		set lstApps to application processes where its creator type = strAppCode
		if length of lstApps < 1 then return missing value
		tell first item of lstApps
			-- GET THE TOP LEVEL MENU
			set strMenu to item 1 of lstMenu
			set oMenu to menu strMenu of menu bar item strMenu of menu bar 1
			
			-- TRAVEL DOWN THROUGH ANY SUB-MENUS
			repeat with i from 2 to (lngChain - 1)
				set strMenu to item i of lstMenu
				set oMenu to menu strMenu of menu item strMenu of oMenu
			end repeat
			
			-- AND RETURN THE FINAL MENU ITEM
			try
				return menu item (item -1 of lstMenu) of oMenu
			on error
				return missing value
			end try
		end tell
	end tell
end GetMenuItem

on GUIEnabled()
	tell application id "sevs"
		if UI elements enabled then
			return true
		else
			activate
			display dialog "This script depends on enabling access for assistive devices in system preferences" buttons "OK" default button "OK" with title pTitle & "   " & pVer
			tell application id "sprf"
				activate
				set current pane to pane id "com.apple.preference.universalaccess"
			end tell
			return false
		end if
	end tell
end GUIEnabled

Last edited by RobTrew; 2012-05-18 at 02:07 PM..