【问题标题】:Programmatically enable MAC OSX Assistive Technologies?以编程方式启用 MAC OSX 辅助技术?
【发布时间】:2012-04-05 02:04:40
【问题描述】:
是否可以在 Snow Leopard、Lion 和 Mountain Lion 上以编程方式启用 MAC OS X 辅助技术?
我有一个客户端,其应用程序需要在 Universal Access 中选中“启用辅助设备访问”复选框。这是针对预计将在 Snow Leopard、Lion 和 Mountain Lion 上运行的应用程序。
可以通过 Applescript 或嵌入在 Objective C 应用程序中的 shell 脚本来完成,还是必须由用户明确手动启用?
【问题讨论】:
标签:
macos
applescript
assistive-technology
【解决方案1】:
这是我使用的...
enable_GUI_scripting()
on enable_GUI_scripting()
try
if (system attribute "sysv") < 4138 then display dialog "This script requires the installation of Mac OS X 10.3 or higher." buttons {"Cancel"} default button 1 with icon 2
tell application "System Events" to if not UI elements enabled then
tell me
activate
display dialog "This script requires the built-in Graphic User Interface Scripting architecture of Mac OS X, which is currently disabled." & return & return & "Enable GUI Scripting now? (You may be asked to enter your password.)" buttons {"Cancel", "Enable"} default button 2 with icon 2
end tell
set UI elements enabled to true
if not UI elements enabled then error number -128
end if
return "yes"
on error
return "no"
end try
end enable_GUI_scripting
【解决方案2】:
试试这个:
tell application "System Events"
activate
set UI elements enabled to true
end tell