I'm trying to execute some JS code as a Node shell script, but it doesn't seem to work and I can't tell why. Here's a simple example:
#!/usr/bin/env node
console.log("foo");
The above script should result in TextExpander inserting the text "foo" when triggered, but it doesn't. The equivalent in bash works just as expected:
#!/usr/bin/env bash
echo "foo"
I thought that perhaps the call to console.log()
was not producing something where TextExpander was looking (although all the documentation I can find says that should print to stdout). I've even tried a workaround like this with no luck:
#!/usr/bin/env sh
echo `/usr/bin/env node -e "console.log(\"foo\");"`
I get no visible errors or any indication that something went wrong. I just end up with TextExpander inserting an empty string instead of "foo"
. Any TextExpander experts out that that might see something I'm missing? Running the non-working examples in the shell work fine, and TextExpander is supposed to just capture whatever goes to stdout. I'm not even sure how I could go about debugging this.
Make sure the directory where your node
executable is installed is listed in the PATH environment variable that TextExpander will use. This is probably not the same PATH value one you get in your terminal. To verify if that's the problem, try doing #!/full/path/to/node
as your shebang line instead of running env
. My guess is node is installed either in /usr/local/bin/node
or somewhere under your home directory and neither of those are in the PATH that TextExpander has while running.