1

I have a call (“mercury-parser” via Yarn, using the full path to the call) that converts Web pages to lines of structured text (the page used in the call describes the service):

/Users/me/.yarn/bin/mercury-parser https://postlight.com/trackchanges/mercury-goes-open-source

If I run it in Terminal (using either /bin/bash or /bin/sh on a 2013 Mac Pro, macOS 10.14.5), I get the proper result: fourteen lines of structured text from the Web page.

However, the very same call returns an error when run as a single-line, “do shell script” AppleScript:

do shell script "/Users/me/.yarn/bin/mercury-parser https://postlight.com/trackchanges/mercury-goes-open-source"

The error returned is:

error "env: node: No such file or directory" number 127

FWIW, here are both my .profile and my .bash_profile texts (the latter created solely to try and solve this quandary), that should not be necessary, given that the full path to the call is being specified, specifically to avoid such an error:

export PATH="/usr/local/bin:/usr/local/sbin:/usr/local/mysql/bin:$PATH"

export PATH="$HOME/.yarn/bin:$HOME/.config/yarn/global/node_modules/.bin:$PATH"

[[ -s $HOME/.nvm/nvm.sh ]] && . $HOME/.nvm/nvm.sh  # This loads NVM

source ~/.nvm/nvm.sh

export NVM_DIR="$HOME/.nvm"
[ -s "$NVM_DIR/nvm.sh" ] && . "$NVM_DIR/nvm.sh" # This loads nvm

What do I have to do to get the call to run as an AppleScript?

[2019.6.26 at 11:25:45PM: Edited in an attempt at clarification.]

2019.6.27 at 1:36:57PM: Per Mark’s suggestion:

Thank you, Mark; I duplicated my .[bash_]profile, renamed it to “.bashrc”, and added “bin/bash” to the call:

do shell script "bin/bash; /Users/RF/.yarn/bin/mercury-parser https://postlight.com/trackchanges/mercury-goes-open-source"

However, (after a reboot) I still get the same error:

error "env: node: No such file or directory" number 127

Thoughts?

  • 1
    .bash_profile is only run for login shells. Terminal creates login shells, but AppleScript do shell script does not. You either need to add the relevant init steps to the do shell script section, or add them to .bashrc (which runs for non-login shells). It's for reasons like this that it's common to either have .bash_profile run .bashrc (and put the init script steps in .bashrc) or vice versa. But you should rewrite it so it doesn't add things to PATH over & over. See this question. – Gordon Davisson Jun 25 at 21:23
  • I’m going to try and clarify things and remove the TIA / chit chat. Thanks for being gracious - but the site prefers no tags / signatures and you can put that all in your linked profile if needed. – bmike Jun 25 at 21:25
  • It’s a shell/env issue indeed. Nothing node specific. – John Keates Jun 27 at 8:58
  • Your path setting should be in ~/.bashrc. Running from desktop ie via automator does not go through a login shell so nothing in ~/.bash_profile is loaded. For the terminal ~/.bash_profile will be read - and that needs to source ~/.bashrc to save typing the commands twice. – Mark Jun 27 at 10:35
  • Thank you, John; that was my assumption. Should I correct the title? What do you suggest? – Richard Fairbanks Jun 27 at 20:29
1

This is a great question and you might need to pass us (or github / pastebin) the actual script.

Barring that, you could do two things to make this a minimal, complete, verifiable question where we might be able to recommend script changes.

  1. Find out exactly which line in your script is failing by setting debugger “set -x” and posting the results / line numbers leading up to the end error.
  2. Make a second script that just runs env node or whatever needed and failing and adding that to the post above.

If you find your error, you can do things in terminal to find the full path to each call and then your script can run in limited environments and not need the terminal setup profile dot files.

which env

Would tell you to change your script to call /usr/bin/env and same for nvm and any other programs that get no such file or directory since it’s likely your script assumes things relative to the current directory or has some variables set.

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .