2
votes

My code is

NSAppleScript* scriptObject = [[NSAppleScript alloc] initWithSource:
                               @"\
                               tell application \"System Preferences\"\n\
                               set current pane to pane id \"com.apple.preference.energysaver\"\n\
                               end tell\n\
                               tell application \"System Events\"\n\
                               tell process \"System Preferences\"\n\
                               tell window 1\n\
                               tell group 1 -- automatic graphics switching\n\
                               tell checkbox 1 -- automatic graphics switching\n\
                               click\n\
                               end tell\n\
                               end tell\n\
                               end tell\n\
                               end tell\n\
                               end tell"];

returnDescriptor = [scriptObject executeAndReturnError: &errorDict];

it's intend to change Graphics automatically,when I try it,I have that error

System Events got an error:“mactest”is not allowed for assistive access

I'm sure the code is correct,it works well in AppleScript Editor,and also ran without error if delete "click\n\" line. And I'm already add my app as well as AppleScript Editor into Security & Privacy,but still useless.

1

1 Answers

1
votes

I believe I've run into this issue as well. I wanted to make a small AppleScript to focus and maximize StepMania. I exported it as an App so I could add it to the login items. Adding in the maximizing functionality worked after I gave AppleScript Editor accessibility permission.

System Preferences -> Security & Privacy -> Privacy -> Accessibility -> AppleScript Editor

However, after exporting it as an application, it was now not running through AppleScript Editor and did not have the required accessibility permission.

AppleScript app is not allowed assistive access

You need to give your App accessibility permissions.

AppleScript app would like to control this computer using accessibility features

Some dialog like this might lead you to dragging your app to the list.