View Single Post
I think it would need to work something like this:

Code:
-- ZOOM ALL CANVASES IN CURRENT OMNIGRAFFLE DOCUMENT TO FIT WHOLE DIAGRAM

property pTitle : "Zoom All Canvases to Fit"
property pVer : "1.0"

property plstMenuItem : {"View", "Zoom", "Fit in Window"}

on run
	if not GUIEnabled() then return
	
	-- GET A REFERENCE TO VIEW > ZOOM > FIT IN WINDOW
	set mnuFitWindow to GetMenuItem("OGfl", plstMenuItem)
	
	-- LOOP THRU EACH CANVAS 
	-- OF THE FRONT WINDOW OR FULL-SCREEN WINDOW
	tell application id "OGfl"
		activate
		if my isFullScreen("OGfl") then
			set oWin to window 2
		else
			set oWin to window 1
		end if
		
		tell oWin
			try
				set oFrontCanvas to its canvas
			on error
				return
			end try
			
			repeat with oCanv in canvases of its document
				set canvas of it to oCanv
				
				-- CLICK ZOOM TO FIT IN WINDOW
				tell application id "sevs" to click mnuFitWindow
			end repeat
			set its canvas to oFrontCanvas
		end tell
	end tell
end run


-- 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
			return menu item (item -1 of lstMenu) of oMenu
		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

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

Last edited by RobTrew; 2011-12-29 at 10:43 AM.. Reason: Edited code: Finder version is faster than sysinfo system version