Setting multiple env. variables using launchctl

Hi, I am trying to get a few 3D programs to work together but one of them requires me to set multiple environment variables for the same key to function properly, however, I seem to be unable to solve how to get that done. All my other variables works and ONE of the two works, but not both.


Here is the current code:

do shell script "launchctl setenv MAYA_MODULE_PATH /Applications/Yeti/Yeti-v2.0.12_Maya2015-darwin64"


do shell script "launchctl setenv RLM_LICENSE 5053@localhost"


do shell script "launchctl setenv YETI_TMP /Applications/Yeti/Yeti-v2.0.12_Maya2015-darwin64/tmp"


do shell script "launchctl setenv YETI_HOME /Applications/Yeti/Yeti-v2.0.12_Maya2015-darwin64"


do shell script "launchctl setenv DYLD_LIBRARY_PATH /Applications/Yeti/Yeti-v2.0.12_Maya2015-darwin64/bin"


do shell script "launchctl setenv LD_LIBRARY_PATH /Applications/Yeti/Yeti-v2.0.12_Maya2015-darwin64/bin"


do shell script "launchctl setenv VRAY_PLUGINS_x64 /Applications/Yeti/Yeti-v2.0.12_Maya2015-darwin64/bin"


do shell script "launchctl setenv VRAY_FOR_MAYA2015_x64 /Applications/Autodesk/maya2015/vray/bin,/Applications/Yeti/Yeti-v2.0.12_Maya20 15-darwin64/bin"


It's the last one that is causing troubles. I also have this in a custom script which runs on startup in order to load them every time I start the computer and before I start any applications.


Thank you in advance for any help, tips or tricks!

MacBook Pro with Retina display

Posted on Nov 15, 2015 10:08 PM

Reply
7 replies

Nov 16, 2015 5:11 AM in response to Aurori_Swe

I don't know if I can be of much help, but do shell script has a few issues with some things due to the script needing to be quoted. I can't be certain, but wonder if the comma in the last one is causing the problem with do shell script.


Can you run that that las line in the Terminal (without do shell script) and it is successful?

If so, maybe try putting the script inside single quotes.


Another option would be to create a single shell script with all the commands and load it via a launch agent. You would need to use Applescript and the do shell script command at all.

Search for creating launch agent plists.

Here's the first hit I got: https://robots.thoughtbot.com/example-writing-a-launch-agent-for-apples-launchd which links back to the Apple developer site for more info.

Here is a discussion that features a launchd plist for running a shell script file. I would put the shell script in some folder in /Library/Application Support/ as opposed to in some users folder unless it only applies to that user, then I would put it in the user's Library.

Creating a Launch Daemon plist to run at startup

The plist can go into the /Library/LaunchAgents folder so that it runs for all users, or put it in an individual user's ~/Library/LaunchAgents folder to only run for that user.

Nov 16, 2015 5:33 AM in response to Aurori_Swe

Another issue could be that do shell runs the /bin/sh which is in the bourne shell family, where setting environment variables is done via the export command

export var="value"

Also the export command can have multiple assignments on a single line

export var1="value" var2="value" var3="value" ...

Unless launchctrl has some magic that requires the use a csh/tcsh syntax.

Nov 30, 2015 9:53 PM in response to Barney-15E

The problem seems to be that Mac no longer allows me to set DYLD_LIBRARY_PATH since it's a security issue or something...


That means that I can't set the variables I need to be able to do my work on a mac.


However, the environments used in my original post works fine besides it and the only issue with my original is to get it to accept two different variables for one key. But since DYLD doesn't work, none of the others matters since I won't be able to render without setting DYLD anyway.


Thank you all for your help though.


Cheers

This thread has been closed by the system or the community team. You may vote for any posts you find helpful, or search the Community for additional answers.

Setting multiple env. variables using launchctl

Welcome to Apple Support Community
A forum where Apple customers help each other with their products. Get started with your Apple Account.