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.