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.
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.
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.
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.