使用 GUI Applescript 解锁系统偏好设置

发布于 2024-12-06 11:07:22 字数 1173 浏览 0 评论 0原文

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

请帮忙。谢谢。

I am trying to unlock the System Preferences using applescript.

I have managed to get my script to click the "Click the lock to make changes" part, and I was trying to get the applescript to enter the user name, but I keep getting the error

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

Here is my code, can anyone give me a hand?

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

Please help. Thank you.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

在风中等你 2024-12-13 11:07:22

这可以使用系统事件的“击键”命令输入密码来完成。 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

This can be done using the System Events' "keystroke" command to type in a password. Yosemite version (UI elements have moved around):

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
沫雨熙 2024-12-13 11:07:22

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

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

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

The authentication dialog is a special sort of thing in OS X; it is implemented in a secure way where it at least cannot be read by key loggers.

I would be surprised if it was possible to script, both as a side effect of this and because it seems to introduce potential security holes.

So you're probably out of luck, sorry.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文