使用GUI Applescript解锁系统首选项

时间:2011-09-26 02:04:35

标签: macos applescript system-preferences

我正在尝试使用applescript解锁系统偏好设置。

我设法让我的脚本点击“点击锁定以进行更改”部分,我试图让applescript输入用户名,但我一直收到错误

error "System Events got an error: Can’t get window 1 of process \"SecurityAgent\". Invalid index." number -1719 from window 1 of process "SecurityAgent"

这是我的代码,任何人都可以帮我一把吗?

activate application "System Preferences"
tell application "System Events"
    set preferencesLocked to false
    tell process "System Preferences"
        delay 1
        click menu item "Security & Privacy" of menu "View" of menu bar 1
        delay 2.5
        if title of button 4 of window 1 is "Click the lock to make changes." then
            set preferencesLocked to true
            click button "Click the lock to make changes." of window 1
        end if
    end tell
    if preferencesLocked is true then
        delay 2.5
        activate application "SecurityAgent"
        tell application "System Events"
            tell process "SecurityAgent"
                set value of text field 1 of scroll area 1 of group 1 of window 1 to "username"
            end tell
        end tell
    end if
end tell

请帮忙。谢谢。

2 个答案:

答案 0 :(得分:1)

这可以使用System Events的“keystroke”命令来输入密码。 Yosemite版本(UI元素已移动):

SELECT * FROM `tbsubscribers` s
RIGHT JOIN `tbmessage` tb ON (
  CASE WHEN msg1 = 1 THEN name = 'msg1' END OR
  CASE WHEN msg2 = 1 THEN name = 'msg2' END OR
  CASE WHEN msg3 = 1 THEN name = 'msg3' END
)

答案 1 :(得分:0)

身份验证对话框在OS X中是一种特殊的东西;它以安全的方式实现,至少不能被键盘记录器读取。

如果可以编写脚本,我会感到惊讶,这既是因为它的副作用,也因为它似乎引入了潜在的安全漏洞。

所以你可能运气不好,抱歉。