Setting environment variables via launchd.conf no longer works in OS X Yosemite/El Capitan/macOS Sierra/Mojave?

前端 未结 9 1221
爱一瞬间的悲伤
爱一瞬间的悲伤 2020-11-22 08:07

It looks like the launchd.conf does not load my environment variable anymore. Has anyone else noticed that?

Is there another solution to permanently set

9条回答
  •  终归单人心
    2020-11-22 08:41

    Here are the commands to restore the old behavior:

    # create a script that calls launchctl iterating through /etc/launchd.conf
    echo '#!/bin/sh
    
    while read line || [[ -n $line ]] ; do launchctl $line ; done < /etc/launchd.conf;
    ' > /usr/local/bin/launchd.conf.sh
    
    # make it executable
    chmod +x /usr/local/bin/launchd.conf.sh
    
    # launch the script at startup
    echo '
    
    
    
      Label
      launchd.conf
      ProgramArguments
      
        sh
        -c
        /usr/local/bin/launchd.conf.sh
      
      RunAtLoad
      
    
    
    ' > /Library/LaunchAgents/launchd.conf.plist
    

    Now you can specify commands like setenv JAVA_HOME /Library/Java/Home in /etc/launchd.conf.

    Checked on El Capitan.

提交回复
热议问题