setenv variable with spaces in launchd.conf?

前端 未结 5 930
栀梦
栀梦 2021-01-02 07:58

I\'m a Linux user that just recently got a mac. I\'m trying to set up my IDE and found out that Macs don\'t use .bashrc / .bash_profile / etc. for GUI apps. So, if you have

5条回答
  •  Happy的楠姐
    2021-01-02 08:51

    In 10.13.2, this works for me:

    launchctl setenv MY_VARIABLE 'My value with spaces'

    But to be specific, I'm using Script Editor to create an app (~/StartupEnvVars.app) containing lines like this:

    do shell script "launchctl setenv MY_VARIABLE 'My value with spaces'"

    Then, in Settings|Users|Login Items I add this app as a startup item.

    It works, with this caveat: if I have Terminal and my R app running when I log out, and choose to reopen windows on logging back in, after those apps auto load when I log in, they DO NOT see the environment variables set by StartupEnvVars.app. But, if I close those apps and reopen them, then they see the environment variables.

    If it were Terminal only, I'd use .bash_profile, but I want to set env vars for use in R also. I think there have been about 5 ways to set global env vars in OSX since I started using it. Each major new version has a new way of doing it. Annoying.

提交回复
热议问题