this should now work no matter how the script is called (including symlinks) on both Mac and Linux. + Storing and restoring the original working directory to prevent problems in certain circumstances.
thanks @overdodactyl !!