【问题标题】:Unlock System Preferences using GUI Applescript使用 GUI Applescript 解锁系统偏好设置
【发布时间】:2015-05-19 01:59:15
【问题描述】:

我正在尝试使用 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

请帮忙。谢谢。

【问题讨论】:

  • 您不能编写登录对话框的脚本。我认为这是因为 Apple 不希望其他程序访问您的计算机或其他东西。
  • 我相信这在以前的 OSX 版本中可以正常工作?似乎这是我最近遇到的新事物:|
  • 我可以写一个 sudo 来解锁系统偏好设置吗?嗯

标签: macos applescript system-preferences


【解决方案1】:

这可以使用系统事件的“击键”命令输入密码来完成。 Yosemite 版本(UI 元素已移动):

set thePW to "MY_PASSWORD"
set thePane to "Security & Privacy"

activate application "System Preferences"
delay 1
tell application "System Events"
    tell process "System Preferences"
        click menu item thePane of menu "View" of menu bar 1
        delay 3
        if title of button 1 of window 1 is "Click the lock to make changes." then
            click button 1 of window 1
            delay 2
            keystroke thePW
            keystroke return
        end if
    end tell
end tell

【讨论】:

    【解决方案2】:

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

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

    所以你可能不走运,抱歉。

    【讨论】:

      猜你喜欢
      • 2020-09-16
      • 2016-09-15
      • 1970-01-01
      • 2021-05-28
      • 2021-08-26
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2016-05-12
      相关资源
      最近更新 更多