I followed this similar question to set my environment variables in Yosemite: https://stackoverflow.com/questions/25385934/setting-environment-variables-via-launchd-conf-no-longer-works-in-os-x-yosemite/26179907#26179907

I want to do the same thing, but for sudo

do shell script "sudo launchctl setenv variablename value" with administrator privileges

but somehow, it does not show if I go in a terminal afterwards and run the command:

sudo launchctl getenv variablename

What am I doing wrong ?


Your first line of code is wrong. If you say sudo and with administrator privileges you are doing the same thing twice. If you use the terminal, as you can see, the following works:

$ sudo launchctl setenv TEST true
Password:<you have to insert your password here>
$ sudo launchctl getenv TEST

You could unset the variable with the command:

$ sudo launchctl unsetenv TEST

You don't need an applescript to do that.

|improve this answer|||||
  • I think I didn't mention it, but I am using apple script to load the variables at each reboot! I'll test your solution and see if it works. – etiennenoel Nov 11 '14 at 15:23
  • Using your solution, of not saying sudo and adding with administrator privileges, with AppleScript worked! Thank you – etiennenoel Nov 11 '14 at 15:44

You must log in to answer this question.

Not the answer you're looking for?Browse other questions tagged .