具有管理员权限的JXA等效项

Cod*_*256 2 shell applescript equivalent javascript-automation

在AppleScript中,您可以:

do shell script "echo 'I am (G)root'" with administrator privileges
Run Code Online (Sandbox Code Playgroud)

抱歉.无论如何,shell脚本可以在JXA中运行,如下所示:

var app = Application.currentApplication();
app.includeStandardAdditions = true;
app.doShellScript("echo I am not root :(");
Run Code Online (Sandbox Code Playgroud)

但是,with administrator privileges在JXA中似乎没有相应的内容.有没有我错过的,或者我该怎么做呢?并且不要告诉我使用sudo.它不会起作用.

jac*_*300 7

将选项放在{} - >中app.doShellScript("ls -l", {administratorPrivileges:true});

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


查看StandardAdditions字典,在弹出窗口中选择" JavaScript "而不是" AppleScript "(默认值).

在此输入图像描述