View Single Post
Made some tweaks to the above script as my needs are slightly simpler. As opposed to zooming each page to the maximum size to fit all objects, my edit simply goes through each page and hits the "Fit in Window" menu command. I realised afterwards this was my mistake for requesting the wrong menu command in the first place. Taking out the object selection saving/select all/zoom/reset selection code also had the side effect of speeding it up a bit.

Thanks again for your script. This is a huge timesaver for me.

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

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

property pMenu : "View"
property pSubMenu : "Zoom"
property pCmd : "Fit in Window"

on run
	if not GUIEnabled() then return
	
	tell application id "OGfl"
		activate
		tell application id "sevs"
			set lstApps to application processes where name contains "OmniGraffle"
			if length of lstApps < 1 then return
			tell first item of lstApps
				tell menu bar 1
					tell menu pMenu of menu bar item pMenu
						tell menu pSubMenu of menu item pSubMenu
							set mnuZoomFit to menu item pCmd
						end tell
					end tell
				end tell
			end tell
		end tell
		tell front window
			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
				-- ZOOM TO FIT
				tell application id "sevs" to click mnuZoomFit
			end repeat
			set its canvas to oFrontCanvas
		end tell
	end tell
end run

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 "System Preferences"
				activate
				set current pane to pane id "com.apple.preference.universalaccess"
			end tell
			return false
		end if
	end tell
end GUIEnabled