具有管理员权限的 JXA 等效方法

3
在AppleScript中,你可以这样做:
do shell script "echo 'I am (G)root'" with administrator privileges

抱歉。无论如何,可以像这样在JXA中运行shell脚本:
var app = Application.currentApplication();
app.includeStandardAdditions = true;
app.doShellScript("echo I am not root :(");

然而,在JXA中似乎没有与“使用管理员权限”相当的等效功能。我是否漏掉了某些东西?还是应该用其他方式来实现?请不要告诉我使用sudo,这不起作用。
1个回答

9

{} 中使用 Put 选项 --> app.doShellScript("ls -l", {administratorPrivileges:true});

带有多个选项的示例: app.doShellScript("ls -l", {userName:'MyUserName', password:'0123456', administratorPrivileges:true, alteringLineEndings:false});


查看 StandardAdditions 字典,在弹出菜单中选择 "JavaScript" 而非默认的 "AppleScript"。

enter image description here


网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接