tell application "System Events"
if UI elements enabled is true then
tell application "System Preferences"
activate
set current pane to pane id "com.apple.preference.universalaccess"
display dialog "This script requires access for assistive evices be enabled." & return & return & "To continue, click the OK button and enter an administrative password in the forthcoming security dialog." with icon 1
end tell
set UI elements enabled to true
if UI elements enabled is false then return "user cancelled"
delay 1
end if
end tell
当我运行时,我收到错误。 “无法将启用应用程序的UI元素设置为true”
为什么会发生这种情况的任何想法?
额外信息:OS X Yosemite
答案 0 :(得分:0)
我刚刚回答了这个基本问题。请参阅我的回答here。
答案 1 :(得分:0)
启用的UI元素是自OS X Mavericks以来的只读属性。试试这个:
tell application "System Events"
if not UI elements enabled then
display dialog "This script requires access for assistive devices be enabled." & return & return & "To continue, click the OK button and enter an administrative password in the forthcoming security dialog." with icon 2
if button returned of result is equal to "OK" then
do shell script "sudo sqlite3 'Library/Application Support/com.apple.TCC/TCC.db' 'insert or replace into access values (\"kTCCServiceAccessibility\",\"com.apple.ScriptEditor2\",0,1,0,null);'" with administrator privileges
end if
end if
end tell