【问题标题】:osx - Permission denied (126) using AppleScript with Administrator Privilegesosx - 使用具有管理员权限的 AppleScript 的权限被拒绝 (126)
【发布时间】:2016-01-13 17:11:36
【问题描述】:

我正在尝试运行一个脚本来启用我的 Mac (El Capitan) 上的屏幕保护程序密码,但它需要管理员权限。我正在使用 applescript 让脚本以管理员权限自动运行,但我仍然收到 126 权限被拒绝错误。这是我的文件:

激活密码的脚本(需要权限):

# ~/bin/passtrue

osascript -e 'tell application "System Events" to set require password to wake of security preferences to true'

然后我创建了一个 applescript 以管理员权限运行该脚本:

# ~/bin/trueapplescript.scpt

do shell script "/Users/user/bin/passtrue.sh" with administrator privileges

最后我创建了一个shell脚本来调用applescript文件:

# ~/bin/change-via-applescript

osascript /Users/user/bin/trueapplescript.scpt

我在运行 change-via-applescript 文件时不断收到以下错误:

/Users/user/bin/trueapplescript.scpt:30:107: 执行错误:/bin/sh: /Users/user/bin/passtrue.sh: Permission denied (126)

感谢您的建议!

【问题讨论】:

    标签: macos shell applescript admin


    【解决方案1】:

    也许我误解了你想要达到的目标。但是如果你打开“AppleScript Editor”并粘贴以下代码,它应该可以工作:

    set myAppleScriptAsShellScript to "osascript -e 'tell application \"System Events\" to set require password to wake of security preferences to true'"
    do shell script myAppleScriptAsShellScript with administrator privileges
    

    【讨论】:

    • 感谢您的评论。这似乎使它工作。将第一个脚本与 applescript 合并可以解决问题,这很奇怪。我假设它一定与安全有关。
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2021-07-19
    • 1970-01-01
    • 2022-01-02
    • 2012-06-26
    • 1970-01-01
    • 1970-01-01
    • 2018-03-27
    相关资源
    最近更新 更多