如果我将我的 Applescript 给另一个人,他们将不得不手动允许 Applescript 控制他们的计算机,方法是进入系统偏好设置,单击安全和隐私,然后单击隐私,然后是可访问性,最后添加 Applescript。无论如何我可以让Applescript添加它自己,这样他们就不必了?还有其他解决方案吗?因为没有他们这样做,Applescript 就无法点击。
如果没有添加 applescript 以便它可以进行控制,我会收到错误消息“不允许辅助访问脚本编辑器”。
如果我将我的 Applescript 给另一个人,他们将不得不手动允许 Applescript 控制他们的计算机,方法是进入系统偏好设置,单击安全和隐私,然后单击隐私,然后是可访问性,最后添加 Applescript。无论如何我可以让Applescript添加它自己,这样他们就不必了?还有其他解决方案吗?因为没有他们这样做,Applescript 就无法点击。
如果没有添加 applescript 以便它可以进行控制,我会收到错误消息“不允许辅助访问脚本编辑器”。
我相信您正在尝试为设备启用辅助访问。例如,GUI 脚本需要启用此功能。您不能直接启用它,但您可以将用户指向他们需要去的地方。下面确定是否启用了辅助访问,并在该选项所在的位置显示“系统偏好设置”窗格。
tell application "System Events"
set UI_enabled to UI elements enabled
end tell
if UI_enabled is false then
tell application "System Preferences"
activate
set current pane to pane id "com.apple.preference.universalaccess"
display dialog "This script utilizes the built-in Graphic User Interface Scripting architecture of Mac OS x which is currently disabled." & return & return & "You can activate GUI Scripting by selecting the checkbox \"Enable access for assistive devices\" in the Universal Access preference pane." with icon 1 buttons {"Cancel"} default button 1
end tell
end if
这应该足以让您的用户获得提示。
理论上,您可以通过命令行执行此操作:
https://raymii.org/s/snippets/OS-X-Enable-Access-for-assistive-devices-via-command-line.html
例如,在 Lion 和 Mountain Lion 中,它很简单:
touch /private/var/db/.AccessibilityAPIEnabled