The script
library makes it easy to execute system scripts from a remote.
local script = libs.script;
All script functions accept one or more lines to make it easy to write longer scripts.
output = script.apple(
"tell application \"Spotify\"",
"set out to player state",
"end tell"
);
The script functions return 3 values:
out,err,res = script.default(...);
You can easily execute scripts from file using the fs
library:
local src = libs.fs.read("foo.bat");
script.batch(src);
Execute a Windows Batch script.
cd = script.batch("echo %cd%");
Execute a Windows PowerShell script.
process_list = script.powershell(
"ps | Where-Object { $_.Name -eq \"svchost\" }"
);
Execute an AppleScript.
path = script.apple("set out to (path to me)");
Execute a shell script using the default interpreter (typically sh
).
foo = script.shell("echo $PWD");
You can specify a different interpreter with a shebang line:
foo = script.shell(
"#!/bin/bash",
"echo $PWD"
);
Note that on Windows the shell
function creates a Batch file.
foo = script.shell("echo %USERNAME%");
Execute the default script depending on platform.
- Windows:
script.batch
. - Mac OS X:
script.apple
. - Linux/Unix:
script.shell
.