View Single Post
Quote:
Originally Posted by psidnell View Post
I usually want to enable/disable the tool bar and viewbar together.

Code:
tell application "OmniFocus"
	activate
	tell application "System Events" to keystroke "V" using command down
	tell application "System Events" to keystroke "t" using {command down, option down}
end tell
FWIW, if you want scripts which specifically hide or show, rather than toggling (and which don't depend on particular keystroke assignments), you can also check which menu items are available, and click or desist accordingly.
Here's a GetMenuItem() function, with an example of using it to hide the Tool and View bars. (Editing the value of the pblnHide flag to false will turn it into a script for showing the two bars).

Code:
property pblnHide : true -- Edit to false for a script which SHOWS the Tool+View bars

on run
	tell application id "OFOC" to activate
	
	-- Check which menu items are available
	set mnuHideToolBar to GetMenuItem("OFOC", {"View", "Hide Toolbar"})
	set mnuShowToolBar to GetMenuItem("OFOC", {"View", "Show Toolbar"})
	
	set mnuHideViewBar to GetMenuItem("OFOC", {"View", "Hide View Bar"})
	set mnuShowViewBar to GetMenuItem("OFOC", {"View", "Show View Bar"})
	
	-- Click hide or show menus, as indicated by by the pblnHide flag
	tell application id "sevs"
		if pblnHide then
			if mnuHideToolBar is not missing value then click mnuHideToolBar
			if mnuHideViewBar is not missing value then click mnuHideViewBar
		else
			if mnuShowToolBar is not missing value then click mnuShowToolBar
			if mnuShowViewBar is not missing value then click mnuShowViewBar
		end if
	end tell
	
end run

-- Reusable menu functions
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 (OR MISSING VALUE, IF UNAVAILABLE)
			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