3

In AppleScript, you can do:

do shell script "echo 'I am (G)root'" with administrator privileges

Sorry. Anyway, a shell script can be run in JXA like this:

var app = Application.currentApplication();
app.includeStandardAdditions = true;
app.doShellScript("echo I am not root :(");

However, there doesn't seem to be an equivalent of with administrator privileges in JXA. Is there one that I'm missing, or how else should I do it? And don't tell me to use sudo. It won't work.

Coder-256
  • 5,212
  • 2
  • 23
  • 51

1 Answers1

9

Put option in {} --> app.doShellScript("ls -l", {administratorPrivileges:true});

Example with multiple options : app.doShellScript("ls -l", {userName:'MyUserName', password:'0123456', administratorPrivileges:true, alteringLineEndings:false});


Look at the StandardAdditions dictionary, select "JavaScript" in the popup instead of "AppleScript" (the default).

enter image description here

jackjr300
  • 7,111
  • 2
  • 15
  • 25