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

标签 shell applescript equivalent javascript-automation

在 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。它不会工作。

最佳答案

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

多选项示例:app.doShellScript("ls -l", {u​​serName:'MyUserName', password:'0123456', administratorPrivileges:true, alteringLineEndings:false});


查看 StandardAdditions 字典,在弹出窗口中选择“JavaScript”而不是“AppleScript”(默认)。

enter image description here

关于shell - 具有管理员权限的 JXA 等效项,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/35384757/

相关文章:

java - 如何过度设计 shell

linux - 如何在shell脚本中将字符串转换为时间戳

applescript - 如何从命令行而不是 Finder.app 预览文件内容

macos - 检查变量是否为数字 : Applescript

c# - C# 中 pred 和 succ 的等价物是什么?

python-2.7 - 字符串中 %s 的 Python 3 等价物是什么?

linux - 模拟用户输入以使用不同参数多次调用脚本

shell - 将 Jenkins 中的 shell 输出重定向到文件

macos - Applescript 将 Safari 选项卡拆分为新窗口

jQuery 相当于 ExtJS 函数extend()、apply() 和namespace()?