Run a shell script on a Mac
I am looking for examples of the syntax for the commands I can send, specifically how to execute a shell script...
Hi Matt, I'm struggling with this as well. I can't tell from the linux-like examples when one is supposed to escape special characters, like the forward slash.
When I look at
~/.TRIGGERcmdData/debug.logit doesn't seem to record each attempt, i.e., I don't see entries when I execute a trigger from the web. I was sort of expecting something to be written to this log that corresponded with each entry seen under "View Runs" on the web interface.
@Russ, could you clarify:
- what environment variables are inherited by the agent running on the Mac, especially $PATH
- where can I look to find the stdout/stderr result of executing a shell command
- what exactly needs to be escaped, e.g., the inconsistent escaping of the forward slash as shown in the above examples
You don't need to escape forward slashes yourself if you use the GUI editor. Just enter the paths like this: ~/script.sh (to refer to a script in your home directory). You only need to worry about escaping backslashes if you're editing your commands.json file directly.
Here are some tips:
Make your script executable with a command like this:
chmod +x script.sh
The ~ charactor refers to your home folder, so you can put scripts in folders in your home folder, and refer to them in the GUI editor like this: ~/scripts/myscript.sh
Test your script from the bash prompt before testing in the GUI editor, and test using the green Play button in the GUI editor before testing using the Trigger button on the website, and test using that Trigger button before using something like Alexa.
If you want to see the output from your commands, write it to a log file with >> like this:
echo Hi >> ~/log.txt