Nuke: environment variables in macOS Sierra 2017

Environment variables in Nuke can be very useful for working on projects where files are not necessarily saved in identical locations. For example I recently worked on a project where we shared all files using Dropbox. Trouble was, the path to my Dropbox folder was not the same as my colleague. Therefore we set up our Nuke files using relative paths and used an environment variable to point to the root of the project. We also tried using the script path as source, but for some reason it would complain about missing files half the time (could just be related to the non-commercial version).

This method has been tested on macOS 10.12.6 and Nuke 11.0v2.

Environment variables in macOS

Often you’ll find guides that suggest you simply put your environment variables in ~/.bash_profile. While this works for command-line tools, it doesn’t work for Nuke and other GUI applications.

Instead, you create a plist file, which executes the launchctl utility that enables you to set an environment variable for GUI applications.

Executing the following command in Terminal creates an environment variable that can be accessed in Nuke:

launchctl setenv MY_ENV /path/to/folder

To set this environment during startup, create a plist file and edit it by opening Terminal and executing:

nano ~/Library/LaunchAgents/NukeEnvironmentVariable.plist

This opens an empty file using the nano text editor. Now paste in

<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "">
 <plist version="1.0">

By convention, you write the name of your “application” on line 6, the string-value for the “Label” key. The important parts you want to replace are “MY_ENV” on line 11 and “/path/to/folder” on line 12.

You may need to change permissions for the file using Terminal like so:

sudo chmod 644 ~/Library/LaunchAgents/NukeEnvironmentVariable.plist
sudo chmod +x ~/Library/LaunchAgents/NukeEnvironmentVariable.plist

Restart macOS.

Getting environment variables in Nuke

To test your new environment variable, open up Nuke, hit “s” on the keyboard and type in the following TCL command:

getenv MY_ENV

To setup your project path to use your new environment variable, hit “s” on the keyboard to open the project settings. In the “project directory” field, type in

[getenv MY_ENV]

Now you can use this path for all your read, write and precomp nodes. Say you had a file “video.mp4” in a folder named “footage” in the root of your project folder. Then instead of typing the full path, which may look something /Users/JohnDoe/Documents/SecretProject/footage/video.mp4, you’d simply type ./footage/video.mp4. The ./ means “from the root of the project directory, go to…”. Similarly ../ means “from the root of the project directory, go back one folder, then go to…”. You can combine multiple ../ to go back several folders like ../../../OtherProject/video2.mp4.