2016-01-13 167 views
1

我想运行一个脚本来启用我的mac(El Capitan)上的屏幕保护程序密码,但它需要管理员权限。我正在使用applescript让脚本自动以管理员权限运行,但我仍然得到了126权限被拒绝的错误。下面是我的文件:osx - 权限被拒绝(126)使用AppleScript和管理员权限

激活密码的脚本(需要许可):

# ~/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 

我一直得到f当我运行更改通过苹果脚本文件时出现错误:

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

感谢您的任何建议!

回答

1

也许我误解了你试图达到的目标。但是,如果你打开“AppleScript编辑器”并粘贴下面的代码,它应该工作:

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 
+0

感谢您的评论。这似乎得到它的工作。奇怪的是,将第一个脚本与applescript合并可以解决问题。我假设它必须与安全有关。 –