Background: texdoc is a command installed by the LaTeX distribution MacTeX and which texdoc
in the Terminal gives "/Library/TeX/texbin/texdoc".
In the Terminal, texdoc --version
gives:
Texdoc 3.4.1 (2022-03-19).
But in AppleScript, via do shell script
, this didn't work.
do shell script "/Library/TeX/texbin/texdoc --version"
gives the error:
error "env: texlua: No such file or directory" number 127.
I don't understand why AppleScript speak about "texlua" not found and "env" (by the way which texlua
gives "/Library/TeX/texbin/texlua").
How to call texdoc
with do shell script
?
Edit
In fact, not only I can not call directly texdoc --version
, but after this is resolved by append /Library/TeX/texbin:
to the path, a real usage case is still not working, eg do shell script "texdoc url"
, even if I append /Library/TeX/texbin:
to the path. Applescript complaints that it does not find the open
command (open
is called by texdoc
to display the pdf documentation. Very strange, because when called directly, eg do shell script "open /usr/local/texlive/2022/texmf-dist/doc/latex/url/url.pdf"
, this works.
So, after adding export PATH='/Library/TeX/texbin:$PATH';
, the AppleScript code :
do shell script "export PATH='/Library/TeX/texbin:$PATH'; texdoc url"
outputs this error:
error "sh: open: command not found\rtexdoc error: Failed to execute: open "/usr/local/texlive/2022/texmf-dist/doc/latex/url/url.pdf"" number 1
So what is the complete method to call a binary like texdoc
with AppleScript?
env
in the terminal and then run it in Script Editor withdo shell script "env"
. Note especially the difference in PATH. Then trydo shell script "which tex"
and compare. For some explanation by apple, take a look at their tech note on the subject: TN2065. You can do most stuff, you just need to take this into account.PATH
in an interactive shell, but not in the shell thatdo shell script
creates. Trydo shell script "PATH="/Library/TeX/texbin:$PATH"; texdoc --version"
PATH=/usr/local/bin:/System/Cryptexes/App/usr/bin:/usr/bin:/bin:/usr/sbin:/sbin:/Library/TeX/texbin:/Library/Apple/usr/bin
and by AppleScript, I obtain onlyPATH=/usr/bin:/bin:/usr/sbin:/sbin
. For which tex I obtain/Library/TeX/texbin/tex
in the Terminal and the error"The command exited with a non-zero status." number 1
in AppleScript. But why my command doesn't work when I append the complete path to the CLI command?"
with'
), thanks, but why doesn't my version works despite I have append the complete path to the command?do shell script "export PATH=\"/Library/TeX/texbin:$PATH\" ; echo $PATH"
Your command doesn't include theexport
. I think the same path will be returned either way but I'm not sure that the path will be available to any subsequent commands without the export.