Select a menu item in AppleScript without using “System Events” in 10.9 Mavericks

applescriptautomatorservices

I was just answering another question and was reminded of a new "feature" in Mavericks.

I used to have a number of small Automator Services that took no input but did something useful when tied to a keystroke. The perfect example was one to bring the Terminal to the front. Some of these required selecting a menu item in the application brought to the front such as Bring All to Front.

Now it seems you need to grant "accessability" to every single app so that a universal keystroke will work if the Service uses the System Events AppleScript library.

Anyone know a fix for this?

Best Answer

I don't know how to click menu items without using System Events, but if others get here searching for how to click menu items with System Events:

tell application "System Events" to tell process "Finder"
    click menu item "New Finder Window" of menu 1 of menu bar item "File" of menu bar 1
end tell
tell application "System Events" to tell process "Finder"
    set frontmost to true
    click (menu item 1 where its name starts with "Compress") of menu 1 of menu bar item "File" of menu bar 1
end tell
tell application "System Events" to tell process "Finder"
    set frontmost to true
    tell menu bar item "File" of menu bar 1
        click
        click menu item "Open With" of menu 1
    end tell
end tell

You can allow all currently installed applications to use the accessibility API by dragging them to the list in System Preferences: