Can I use the output of a shell script to set env vars from launchd?
3
votes
2
answers
284
views
I'm using
launchd
to set an env var at startup using launchctl setenv
.
The script works fine when the variable is hardcoded in it, but unfortunately I need to get this variable dynamically at startup from a script.
The reason I'm trying to use launchd
for this (rather than using .zshrc
to run export MYVAR=...
) is that the script will prompt me for a password before returning the desired value, and I don't want to enter the password every single time I open a shell.
If I were using Linux, I could simply use .zprofile
for this, which is only sourced for login shells, which only happens at system login. But this is MacOS: **every** shell is a login shell, and so every shell sources .zprofile
together with the rest of files. Hence my attempt at doing this in launchd
.
So my question is:
Is there any way for launchd to "read" the output from an interactive shell script, and then use that output as input for the launchctl setenv
command?
Asked by VMX
(141 rep)
Jun 29, 2023, 05:29 PM
Last activity: Jul 1, 2023, 10:07 AM
Last activity: Jul 1, 2023, 10:07 AM