AppleScript 中的用户属性/权限
我想编写一个 applescript 程序,首先检查用户是否具有管理员权限,如果没有,则请求重新登录或其他操作。
最终,该脚本需要对我刚刚创建的文件夹执行 sudo chmod...我可以使用 do 脚本和管理员权限来完成此操作。
但是我还没有弄清楚如何为 applescript 命令请求管理员权限,或者甚至只是检查用户是否具有管理员权限。
有人知道吗?或者至少给我指出一个好的 applescript 参考文献? (Apple.com 参考资料对我没有帮助)
谢谢。
I want to write an applescript program that first checks to see if the user has Admin privileges, and if it doesn't then requesting a re-log-in or something.
Eventually the script is going to need to do a sudo chmod of a folder I just created... I can do that with a do script and a with Administrator Priviledges.
However I haven't figured out how to either request admin privs for an applescript command, or even just check if the user HAS admin privs.
Anyone know? or at least point me at a GOOD applescript ref? (Apple.com reference is not helping me)
thanks.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(5)
来自苹果论坛的解决方案:
似乎可以解决问题。它很难阅读,正如 Philip Regan 所说,我是通过命令行完成的,但它似乎给了我所需的保护......
A solution from the Apple forum:
seems to do the trick. It's hard to read, and as Philip Regan said, I'm doing it via the command line, but it seems to give me the protection that I need...
只需使用
具有管理员权限
即可。如果用户没有管理员权限,Applescript 将提示他们输入名称和密码。使用try ... on error
块,以防用户取消、输入错误密码或只是没有管理员权限。如果您确实想知道当前用户是否是管理员,请检查该用户是否在 admin 组中:
Just use the
with administrator privileges
. If a user doesn't have admin privileges, Applescript will prompt them for name and password. Use atry ... on error
block in case the user cancels, enters the wrong password or just plain doesn't have admin rights.If you really want to know if the current user is an administrator, check that the user is in the admin group:
这是另一种尚未有人提及的替代解决方案。
dscl 命令允许您执行各种目录服务任务
,其中之一是能够查找用户的帐户类型。
命令:dscl。读取/Groups/admin GroupMembership
将列出 OS X 上的所有 admin
帐户。
因此,如果您想将其合并到 AppleScript 中,您可以执行以下操作:
一旦确定变量 isAdmin 是 true 还是 false,您就可以
执行多种功能。此外,如果脚本是通过 ARD 部署或发送的,您可以设置 userName 变量(上述脚本中的第一行)以使用 whoami 命令检查当前用户。所以第一行看起来像这样:
Here's another alternative solution which no one mentioned yet.
The dscl command allows you to perform a variety of Directory Service tasks
and one of them is the ability to look up a user's account type.
The command: dscl . read /Groups/admin GroupMembership
will list all admin
accounts on OS X.
So if you wanted to incorporate that into an AppleScript you could do the following:
Once you find out whether the variable isAdmin is true or false you can then
perform a variety of functions. Also, if the script was being deployed or sent through ARD you could set the userName variable (the first line in the above script) to check for the current user with a whoami command. So the first line would then look like this:
我有点恼火的是系统事件在用户对象中没有为此的属性,但基于 id 和 dscl 的查询似乎是最好的选择。为了便于阅读,我使用:
注意 admin 周围的空格。这可以防止它与 lpadmin 等组混淆。
I'm a little annoyed that System Events doesn't have a property in the user object for this, but the id and dscl based queries seem the best bet. For readability I use:
Note the spaces around admin. This prevents it form being mixed up with groups like lpadmin.
通过 MacScripter.net 这应该是一个开始:管理权限(第 2 页,共 2 页)
Via MacScripter.net this should be a start: Managing Permissions (page 2 of 2)