Thank you for answering a question that I did not ask, the answer to
which I knew and was not helpful. Which was unsurprising.
As the script is used by the User (only), $EUID is the same whether
started interactively or by launchd.
However, for those who might be interested, I found that you can easily
put something like
<key>EnvironmentVariables</key>
<dict>
<key>RUNNING_UNDER_LAUNCHD</key>
<string>1</string>
</dict>
</key>
into the plist and then check $RUNNING_UNDER_LAUNCHD.
If yo want to be sure you can set RUNNING_UNDER_LAUNCHD to 0 in .bashrc.
Then of course one can check for $PPID which is 1 if turned loose by
launchd.
And then finally is $XPC_SERVICE_NAME which you (can) set with
<key>Label</key>
<string>na.lisse.whatever.run</string>
in the plist and on an interactive shell is 0.
So, bottom line, RTFM :-)-O
el
On 08/02/2022 20:09, Lewis wrote:
In message <j6f4rcFu3g7U2@mid.individual.net> Dr Eberhard Lisse <nospam@lisse.NA> wrote:
Hi,
how can a (bash) script find out whether it runs under launchd?
the usual way to see how a script was launched is to check the EUID,
but I am not sure that will tell you with launchd
For example, to check if the script was launched by root:
if [[ $EUID -ne 0 ]]; then
echo "root user required"
exit 1
fi
--
To email me replace 'nospam' with 'el'
--- SoupGate-Win32 v1.05
* Origin: fsxNet Usenet Gateway (21:1/5)