执行脚本时AppleScript使用哪个用户 [英] Which user is AppleScript using when executing scripts

查看:158
本文介绍了执行脚本时AppleScript使用哪个用户的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

•这是通过AppleScript执行的脚本:

• Here is the script to be executed via AppleScript:

bash-3.2$ cd /Users/jack/Desktop/
bash-3.2$ ls -l | grep static
-rwxrwxrwx   1 jack  admin      65  5 May 08:10 static-routes.sh
bash-3.2$ cat static-routes.sh 
#!/bin/bash
sudo route -n add -net 192.168.3.0/24 172.16.254.134
~                                                         

•AppleScript包含以下内容:

• AppleScript contains the following:

do shell script "~/Desktop/static-routes.sh"

•在AppleScript中执行脚本时,通过单击运行"按钮,弹出窗口,显示:

• When executing the script from within an AppleScript, by clicking on "Run" button, pop up window saying:

脚本错误sudo:需要终端读取密码;使用-S选项从标准输入中读取或配置一个AskPass助手

Script Error sudo: a terminal is required to read the password; Either use the -S option to read from standard input or configure an askpass helper

•在没有 sudo 的情况下从控制台执行脚本时,不会出现其他提示:

• When exeucuting script from the console without sudo, no additional prompts appear:

bash-3.2$: Desktop jack$ ./static-routes.sh 
add net 192.168.3.0: gateway 172.16.254.134

•这是/etc/sudoers 中的代码段:

bash-3.2$ sudo visudo
# root and users in group wheel can run anything on any machine as any user
root            ALL = (ALL) ALL
%admin          ALL = (ALL) ALL
jack ALL = (ALL) NOPASSWD: /Users/jack/Desktop/static-routes.sh

## Read drop-in files from /private/etc/sudoers.d
## (the '#' here does not indicate a comment)
#includedir /private/etc/sudoers.d
Defaults timestamp_timeout=60

问题:

•为什么会出现此错误,因为我已将脚本显式添加到sudoers文件中,因此无需通过sudo进行密码提示即可执行该脚本?

• Why this error is showing up, since, I have explicitly added the script to the sudoers file to be executed without password prompt via sudo?

•AppleScript使用哪个用户来执行脚本?可以修改吗?

• Which user does AppleScript use to execute the scripts? Is it possible to modify it?

推荐答案

运行需要AppleScript特权的命令,您需要通过添加 administrator特权键来指定,例如以下:

The run a command that requires privileges from AppleScript, you need to specify that by adding the administrator privileges key, as in one of the following:

-- this will presented a standard authorization dialog
do shell script "~/Desktop/static-routes.sh" with administrator privileges

-- this will specifies an administrator account and password
-- (though note, the password will be visible as plain text in the script)
do shell script "~/Desktop/static-routes.sh" with administrator privileges user name XXXX password YYYY

您不应同时使用具有管理员权限的 sudo ; 这是不必要的,并且会造成安全漏洞.但是,由于您已经更改了sudoers文件,因此可以尝试以下操作:

You should not use sudo at the same time you use with administrator privileges; it's unnecessary and creates security holes. However, since you've changed the sudoers file already, you could try this:

do shell script "sudo ~/Desktop/static-routes.sh"

像这样预先放置 sudo 可能会提示AppleScript做正确的事情.

Putting sudo up front like that might cue AppleScript to do the correct thing.

请参见

See Technote 2065 for more information.

这篇关于执行脚本时AppleScript使用哪个用户的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆