ACtl.runCommand
This function is the API counterpart of the open file/program action. It can execute commands, run programs and open files.
ACtl.runCommand(command[,workingDir][,getOutput]) command Type: string
Any command line, program or file that can be run via the system shell.
File paths must be enclosed in quotes if they contain spaces.
workingDir Type: string Default: <desktop>
Path of the directory in which to run command. It can be relative to the script's location (if there is one). It can also contain placeholders such as <desktop>, <documents> and others.
It cannot be omitted if you pass a string to the getOutput argument.
getOutput Type: boolean | string Default: false
true or false for whether or not to retrieve command's stdout stream.
It can also be the string 'UTF-16', in which case the output stream is interpreted as double-byte unicode characters.
Shell commands such as dir need this in order to show non-Latin characters correctly.
Returns Type: Promise Resolves to: Object
Returns immediately. The Promise will resolve when command has finished.
The resolved value will be an object with the following properties:
exitCode Type: number
The exit code returned by command.
stdout Type: string
The contents of command's stdout stream.
This property won't be present if getOutput is false.
Throws Type: string
Error description if the system fails to run command.
Examples
Get the list of files and folders in the desktop.
//Execute the DIR command and get its output
let {stdout} = await ACtl.runCommand('dir /b', true) ;
//Split the output in lines. Each line is a filename
for( let filename of stdout.split('\n') )
console.log(filename) ;
Take a screenshot of the tab the script is running in and open it in the default image viewer.
//Capture the tab the script is running in
let [[, dataUri]] = await ACtl.captureTab() ;
//Save the image to a PNG file in the desktop
let filePath = await ACtl.saveURL(dataUri, '<desktop>/tab capture.png') ;
//Open the image file (between quotes to guard for spaces)
await ACtl.runCommand(`"${filePath}"`) ;