Take the 2-minute tour ×
Ask Different is a question and answer site for power users of Apple hardware and software. It's 100% free, no registration required.

There are different solutions regarding the definition of environment variables that are stored in the launchd process, namely over at StackOverflow and Superuser. How do these solutions differ?

share|improve this question

1 Answer 1

up vote 2 down vote accepted

For the sake of clarity, I will refer to this solution as the static solution, the second solution as the dynamic solution, and finally this one as the launch agent solution. I am going to compare the static and dynamic solution with the launch agent one, respectively.

The static solution involves the editing of /etc/launchd.conf. This has the advantage, as with the launch agent solution, that the variables are set right at the login. Disadvantages are that

  • the variables are defined for all users. The launch agent solution lets each user decide for himself. If one wants to define variables for all users with the launch agent solution, the shell script can be amended with a loop (and another file),
  • the definition of the variables in /etc/launchd.conf does not allow for things like variable substitution and such stuff (at least that is my guess, maybe it is feasible),
  • obviously, you need access to /etc/launchd.conf to pull the static solution off, with the other one you can put all files at accessible places, e.g. the launch agent in ~/Library/LaunchAgents/,
  • the variables are not available immediately after editing the file, as with the launch agent solution (but see below).

The dynamic solution is similar to the launch agent solution. Its disadvantage is that the variables are not available right after login, you first need to (re-)define them. To combine the dynamic solution with the other, imagine you wanted to set the variable FOO to the content of the variable BAR. You would fire up a shell, say the bash, and type

launchctl setenv FOO "$BAR"
echo 'setenv FOO $BAR' >> ~/.conf.launchd

Then FOO would be available in all applications started after this definition, and would also be defined right after the next login.

share|improve this answer

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.