AppleScript: Error thrown when trying to read UI elements enabled

倾然丶 夕夏残阳落幕 提交于 2019-12-13 17:47:00

问题


If I run the following from Terminal

osascript -e 'tell application "System Events" to get UI elements enabled'

I get "true" or "false" as expected

But if I were to create a file with the following contents;

#!/usr/bin/osascript

on supportsAssistiveDevices()
  tell application "System Events"
    set isEnabled to UI elements enabled
    return isEnabled as boolean
  end tell
end supportsAssistiveDevices

log supportsAssistiveDevices()

and run it via ./myfile, I get the following error;

./hasguiscript:87:106: execution error: An error of type -10810 has occurred. (-10810)

Can anyone help shed some light on why that might be?

Thanks.


回答1:


This hasn't worked since before 10.9. You do not enable ui elements as one setting. You must enable each individual application that requests access to ui elements. It's a "security" feature and there's no automated way to enable an application. So your code hasn't worked for over a year now.

system preferences->security & privacy->privacy->accessibility


来源:https://stackoverflow.com/questions/26680164/applescript-error-thrown-when-trying-to-read-ui-elements-enabled

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!