Microsoft Word keyboard shortcut to close the sidebar

Feb 27, '13 07:30:00AM

Contributed by: schuyler

Microsoft Word 2011 does not, as far as I can tell, offer a means of assigning a keyboard shortcut to close the sidebar. The AppleScript described here provides that functionality, and sets a keyboard shortcut that will trigger it.

Name the following Applescript "MicrosoftWordCloseSidebar\mosH.scpt" (notice the reversed slash) and save it in ~/Library/Application Support/Microsoft/Office/Word Script Menu Items:

do shell script "osascript -e '
tell application \"System Events\" to tell process \"Microsoft Word\"
 	set {frontmost, itemFound} to {true, false}
 	repeat with w in windows
 		tell w to repeat with g in groups
 			tell g to repeat with c in checkboxes
 				tell c to if value of its attribute \"AXHelp\" = \"Close the Sidebar\" then
 					set itemFound to true
 					click
 					exit repeat
 				end if
 			end repeat
 			if itemFound then exit repeat
 		end repeat
 		if itemFound then exit repeat
 	end repeat
end tell
' >/dev/null 2>&1 &"
When you press Command-Option-Shift-H, the close button of the sidebar is clicked, and the sidebar closes. The keyboard shortcut comes from the "mosH" part of the Applescript name (m=Command, o=Option, s=Shift, H=the letter H). That shortcut was chosen to complement the existing shortcut to open the Find/Replace Sidebar (Command-Shift-H) and may be altered to suit a particular user's needs. The script is constructed as a background osascript to get around a problem that occurs when trying to GUI-script Microsoft Word from its script menu.

Comments (12)


Mac OS X Hints
http://hints.macworld.com/article.php?story=20130217172318170