如何通过Applescript授予Applescript权限?

时间:2014-10-27 15:54:30

标签: applescript system-preferences

如果我将我的Applescript交给另一个人,他们必须手动允许Applescript控制他们的计算机,方法是进入系统偏好设置,点击安全&隐私,然后单击隐私,然后单击辅助功能,然后最后添加Applescript。无论如何,我可以让Applescript添加自己,所以他们不必?还有其他解决方案吗?因为没有他们这样做,Applescript无法点击。

如果没有添加AppleScript以便它可以控制,我会收到错误,"脚本编辑器不允许辅助访问。"

2 个答案:

答案 0 :(得分:0)

我相信您正在尝试为设备启用辅助访问。例如,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

这应该足以让您的用户获得提示。

答案 1 :(得分:0)

理论上你可以通过命令行来完成它:

https://raymii.org/s/snippets/OS-X-Enable-Access-for-assistive-devices-via-command-line.html

例如,在Lion and Mountain Lion中,它很简单:

touch /private/var/db/.AccessibilityAPIEnabled