如何在运行Apple脚本管理员shell脚本的时候会覆盖认证问这个问题? [英] How to overwrite the asking for authentication when running an admin shell script in Apple Script?

查看:287
本文介绍了如何在运行Apple脚本管理员shell脚本的时候会覆盖认证问这个问题?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想使这对UI背后登录每次运行一个简单的程序。在我的AppleScript我跑,需要管理员身份验证的sudo命令。有没有办法每次运行时覆盖认证的需要?我不想让每个这个脚本登录后运行时输入自己的用户名和密码。任何帮助吗? (在非​​常简单的术语为我是一个新手。)
不胜感谢!

I'm wanting to make a simple program that runs each time on login behind the UI. In my applescript I'm running a sudo command that requires admin authentication. Is there a way to overwrite the need for authentication each time it runs? I don't want to have to type my username and password each time this script runs after login. any help? (and in very simple terms to as I'm a novice.) Much Thanks!

推荐答案

您可以把您的用户名和密码在AppleScript的命令,以便它不要求这些凭据。但是请注意,这些项目被存储为AppleScript的内部纯文本,从而有可能给别人看他们。它不是真正的安全,但它是由你来决定它是否安全。注意:你并不需要命令中的命令再

You can put your username and password in the applescript command so that it doesn't ask for those credentials. However note that these items are stored as plain text inside the applescript and thus it's possible for others to see them. It's not really secure but it's up to you to decide if it's safe. NOTE: you don't need "sudo" in the command any longer.

do shell script "whatever" user name "username" password "password" with administrator privileges

有在那里你可以在Keychain存储密码,并从AppleScript的检索方法,从而使得它的安全。如果你想做到这一点,那么你创建密码的项目如下:

There are methods where you can store your password in the Keychain and retrieve it from the applescript, thus making it secure. If you want to do that then you create the password item as follows.

打开钥匙串访问应用程序,并选择左列中的钥匙串。然后单击文件>新建密码项目...,给它一个名字,把你的账号短名称的账户,并输入密码。突出显示它在口令列表中,并获得它的信息。根据属性按钮进入其作为一种通用的密钥。这是选择,因为不会有太多的人,并且搜索速度要快得多。无论你的名字给它必须被放置在code低于您的密码名称。

Open Keychain Access application and select the keychain in the left column. Then click File>New Password Item..., give it a name, put your account shortname in account, and enter the password. Highlight it in the password list and get information on it. Under the Attributes button enter its kind as generic key. This is chosen because there aren't many of them and the search is much faster. Whatever name you give to it must be put in the code below in "Your Password Name".

现在从AppleScript的你可以用它像这样...

Now from applescript you can use it like this...

set myPass to getPW()

do shell script "whatever" user name "username" password myPass with administrator privileges

on getPW()
    do shell script "security 2>&1 >/dev/null find-generic-password -gl \"Your Password Name\" | awk '{print $2}'"
    return (text 2 thru -2 of result)
end getPW

祝你好运!

这篇关于如何在运行Apple脚本管理员shell脚本的时候会覆盖认证问这个问题?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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