Click menu item on Mac OSX Lion using AppleScript
Asked Answered
A

2

4

I have a problem using a simple AppleScript on Mac OSX 10.7.3. With the following simple AppleScript which I find everywhere OSX raises an error 'The action "Run AppleScript" encountered an error'

I open up the Automator, create a Service, drop in a "Run AppleScript" node and enter the following code which I assume is correct because as I said it is the way a lot of people are doing it without any complaints.

AppleScript:

tell application "Terminal" to activate
    tell application "System Events"
        tell process "Terminal"
            click menu item "New Window" of menu "Shell" of menu bar 1
            tell application "Terminal" to close the front window
        end tell
end tell

EDIT: When running in Automator I also get an error description:

Run AppleScript failes -1 error
Access for assistive devices is disabled"
Argumentation answered 27/3, 2012 at 13:7 Comment(1)
This doesn't seem like a programming question but instead a "how to use" or "power user" question best asked on Super User.Plowman
W
4

Is Enable access for assistive devices enabled? If so, have you tried to reenable it?

Wholesale answered 27/3, 2012 at 13:31 Comment(1)
Alright. Seems to be a bug in the Mac OSX system. In System Preferences > Universal Access the selection box Enable access for assistive devices was active what is right for my intention. Now I deactivated it, ran the script again - error. Correct. Then I reactivated, ran the script again - worked! Correct!Argumentation
P
3

Well, I guess I'll answer the question anyways (and thanks for editing your question to give a bit more useful detail).

Go to the "Universal Access" pane in System Preferences and at the bottom of the "Seeing" tab, you'll see a "Enable access for assistive devices" checkbox.

Enable Assistive Devices Turn that on and I suspect Automator will work.

Plowman answered 27/3, 2012 at 13:31 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.