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:
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" "http://www.apple.com/DTDs/PropertyList-1.0.dtd"> <plist version="1.0"> <dict> <key>Label</key> <string>NukeEnvironmentVariable</string> <key>ProgramArguments</key> <array> <string>/bin/launchctl</string> <string>setenv</string> <string>MY_ENV</string> <string>/path/to/folder</string> </array> <key>RunAtLoad</key> <true/> </dict> </plist>
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
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:
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
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
./ 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