create environment variable over plist file

javipcn
New Contributor II

Hi all!

recently arrived to Apple management and I've got a task pending to fix: to setup two environment variables necessary for one GUI application.

I can setup them over a plist file stored in /Library/LaunchAgents, but same plist file doesn't work loading it as a Configuration Profile from Jamf Pro.

If I look for loaded profiles, it appears from Jamf as well as from terminal typing 'profiles list -all', but it doesn't work. Other plist files launched from Jamf are working properly but no for setting environment variables.

Could someone to assist on this?

Thanks a lot in advance

1 ACCEPTED SOLUTION

BGhilardi
New Contributor III

1. Create a LaunchAgent script
Create a com.resolve.env.plist file in /Library/LaunchAgents/ to set the environment for each user launch:

<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN"
"http://www.apple.com/DTDs/PropertyList-1.0.dtd">
<plist version="1.0">
<dict>
<key>Label</key>
<string>com.resolve.env</string>

<key>ProgramArguments</key>
<array>
<string>/bin/launchctl</string>
<string>setenv</string>
<string>BMD_RESOLVE_SUPPORT_DIR</string>
<string>/chemin/personnalise/pour/resolve</string>
</array>

<key>RunAtLoad</key>
<true/>

<key>StandardOutPath</key>
<string>/tmp/resolve_env.log</string>

<key>StandardErrorPath</key>
<string>/tmp/resolve_env.err</string>
</dict>
</plist>

Replace the path "/path/custom/for/resolve" with the actual path you want to use.

2. Deploy via Jamf
Zip the .plist file (or create it via script in a Files and Processes policy).

Place it in /Library/LaunchAgents/ on the target machines via a package or Jamf policy.

You can also use a deployment script in Jamf to automatically copy it:

#!/bin/bash

cat <<EOF > /Library/LaunchAgents/com.resolve.env.plist
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN"
"http://www.apple.com/DTDs/PropertyList-1.0.dtd">
<plist version="1.0">
<dict>
<key>Label</key>
<string>com.resolve.env</string>
<key>ProgramArguments</key>
<array>
<string>/bin/launchctl</string>
<string>setenv</string>
<string>BMD_RESOLVE_SUPPORT_DIR</string>
<string>/chemin/personnalise/pour/resolve</string>
</array>
<key>RunAtLoad</key>
<true/>
</dict>
</plist>
EOF

chmod 644 /Library/LaunchAgents/com.resolve.env.plist
chown root:wheel /Library/LaunchAgents/com.resolve.env.plist

 

3. Restart the user session
Once the .plist is installed, the variable will be set upon user login. If Resolve is subsequently launched, it will be available.

View solution in original post

11 REPLIES 11

sdagley
Esteemed Contributor II

@javipcn Can you post more info on what app and what exactly you're trying to set? While Configuration Profiles are commonly used to manage preferences for an application they can't be used to deploy something to /Library/LaunchAgents, and that is not normally where app configurations are set.

javipcn
New Contributor II

Hi!!

yes, the application is Davinci Resolve and it requires to set a variable called BMD_RESOLVE_CONFIG_DIR to the proper path: '$HOME/Library/Preferences/Blackmagic Design/DaVinci Resolve/' or to other custom path.

Maybe, the best way could be to create a script to execute the setenv command?

Thanks for your quick reply!

sdagley
Esteemed Contributor II

Do you have a reference to the docs with instructions to set that path? I am not familiar with that app, but that location should be the default location for an app to store user specific settings.

javipcn
New Contributor II

It's described in the file "User Configuration folders and customization.txt" copied once the app is installed. In that file you can read as follow for custom locations as it's our case:

 
Overriding paths:
=================
For custom installations, the following environment variables can be used to override the new locations. 
Note that these environment variables need to be set after installation, but before starting Resolve for the first time.
 
BMD_RESOLVE_SUPPORT_DIR: 
The Application support location. If not set, the value defaults to the new Application Support location for each platform.
 
BMD_RESOLVE_CONFIG_DIR: 
The configuration location. If not set, the value defaults to the new Configuration location for each platform.
 
BMD_RESOLVE_LOGS_DIR: 
The location of DaVinci Resolve logs. If not set, the value defaults to $BMD_RESOLVE_SUPPORT_DIR/logs as per the evaluation of BMD_RESOLVE_SUPPORT_DIR above.

...

sdagley
Esteemed Contributor II

Do you need to override the default which would already be in "$HOME/Library/Preferences/Blackmagic Design/DaVinci Resolve/'?

javipcn
New Contributor II

Yes, that's the target, to set the path to another location as default

sdagley
Esteemed Contributor II

Since you mentioned you've "recently arrived to Apple management" I'm going to ask what was the need to use another location? The $HOME/Library/Preferences directory is a standard Apple location and Blackmagic Design appears to have been following that standard.

javipcn
New Contributor II

Yes. We're working in a LAN where others resources are shared. The above examples are just some of the custom setup but there is others, required for us. The default preferenceces and other parameters to be used by Resolve are located in a shared folder.

BGhilardi
New Contributor III

1. Create a LaunchAgent script
Create a com.resolve.env.plist file in /Library/LaunchAgents/ to set the environment for each user launch:

<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN"
"http://www.apple.com/DTDs/PropertyList-1.0.dtd">
<plist version="1.0">
<dict>
<key>Label</key>
<string>com.resolve.env</string>

<key>ProgramArguments</key>
<array>
<string>/bin/launchctl</string>
<string>setenv</string>
<string>BMD_RESOLVE_SUPPORT_DIR</string>
<string>/chemin/personnalise/pour/resolve</string>
</array>

<key>RunAtLoad</key>
<true/>

<key>StandardOutPath</key>
<string>/tmp/resolve_env.log</string>

<key>StandardErrorPath</key>
<string>/tmp/resolve_env.err</string>
</dict>
</plist>

Replace the path "/path/custom/for/resolve" with the actual path you want to use.

2. Deploy via Jamf
Zip the .plist file (or create it via script in a Files and Processes policy).

Place it in /Library/LaunchAgents/ on the target machines via a package or Jamf policy.

You can also use a deployment script in Jamf to automatically copy it:

#!/bin/bash

cat <<EOF > /Library/LaunchAgents/com.resolve.env.plist
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN"
"http://www.apple.com/DTDs/PropertyList-1.0.dtd">
<plist version="1.0">
<dict>
<key>Label</key>
<string>com.resolve.env</string>
<key>ProgramArguments</key>
<array>
<string>/bin/launchctl</string>
<string>setenv</string>
<string>BMD_RESOLVE_SUPPORT_DIR</string>
<string>/chemin/personnalise/pour/resolve</string>
</array>
<key>RunAtLoad</key>
<true/>
</dict>
</plist>
EOF

chmod 644 /Library/LaunchAgents/com.resolve.env.plist
chown root:wheel /Library/LaunchAgents/com.resolve.env.plist

 

3. Restart the user session
Once the .plist is installed, the variable will be set upon user login. If Resolve is subsequently launched, it will be available.

javipcn
New Contributor II

Great BGhilardi, it looks nice. I'll test it as soon as I can do.

Thanks both!

javipcn
New Contributor II

I've deployed the plist file as a package and it's properly copied to the destination folder, so it works!!

Just I need to check because it's installed to the first user loged in, but I need to do for any user so Macos are joined to a Windows domain. But I believe it's another question, maybe to copy the plist to the LaunchAgents from the home folder intead system folder.

Thanks BGhilardi for the tip!