Skip to content

Instantly share code, notes, and snippets.

@bricooke
Created September 30, 2011 02:27
Show Gist options
  • Save bricooke/1252505 to your computer and use it in GitHub Desktop.
Save bricooke/1252505 to your computer and use it in GitHub Desktop.
Note: See comments. You can create custom behaviors in Xcode to do this and that's way better.
-- `menu_click`, by Jacob Rus, September 2006
-- via http://hints.macworld.com/article.php?story=20060921045743404
--
-- Accepts a list of form: `{"Finder", "View", "Arrange By", "Date"}`
-- Execute the specified menu item. In this case, assuming the Finder
-- is the active application, arranging the frontmost folder by date.
on menu_click(mList)
local appName, topMenu, r
-- Validate our input
if mList's length < 3 then error "Menu list is not long enough"
-- Set these variables for clarity and brevity later on
set {appName, topMenu} to (items 1 through 2 of mList)
set r to (items 3 through (mList's length) of mList)
-- This overly-long line calls the menu_recurse function with
-- two arguments: r, and a reference to the top-level menu
tell application "System Events" to my menu_click_recurse(r, ((process appName)'s ¬
(menu bar 1)'s (menu bar item topMenu)'s (menu topMenu)))
end menu_click
on menu_click_recurse(mList, parentObject)
local f, r
-- `f` = first item, `r` = rest of items
set f to item 1 of mList
if mList's length > 1 then set r to (items 2 through (mList's length) of mList)
-- either actually click the menu item, or recurse again
tell application "System Events"
if mList's length is 1 then
click parentObject's menu item f
else
my menu_click_recurse(r, (parentObject's (menu item f)'s (menu f)))
end if
end tell
end menu_click_recurse
-- the activate should be redundant, but just in case
tell application "Xcode" to activate
-- the 'try's are done so it doesn't matter if the menu doesn't exist, which it won't if one is already hidden.
-- probably a better way to do this.
try
menu_click({"Xcode", "View", "Navigators", "Hide Navigator"})
end try
try
menu_click({"Xcode", "View", "Debug Area", "Hide Debug Area"})
end try
try
menu_click({"Xcode", "View", "Utilities", "Hide Utilities"})
end try
try
menu_click({"Xcode", "View", "Hide Toolbar"})
end try
@cparnot
Copy link

cparnot commented Oct 18, 2011

I tried to use it, and had some issue setting it up with behaviors, then realized you could have the same behavior added in the .... behaviors pref of Xcode 4. You can even set up a keyboard shortcut (I use cmd-=).

@bricooke
Copy link
Author

@cparnot - dang, that's awesome. I didn't realize you could create your own behaviors and set shortcuts. Thanks!

@cparnot
Copy link

cparnot commented Oct 20, 2011

You're welcome, but I only found out because of you and trying to get Applescript to run straight from Xcode, so you can thank you too :-)

In any case, I now have an 'All Code' and 'All Chrome' shortcuts, see screenshots http://twitter.com/#!/cparnot/status/126445564199059457 and http://twitter.com/#!/cparnot/status/126445727302950913

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment