8 Replies Latest reply on Oct 3, 2015 6:48 AM by danielafort

    Set system path on Mac?

    danielafort

      I'm helping with a plugin that uses some open source command line tools. The plugin ships with all the dependencies bundled into a "bin" directory which works fine in Windows but the Mac searches the system path when these programs are called. Mac users were told to install the files in /usr/bin but now with "El Capitan" that isn't possible. It also seems that the plugin cannot access anything installed in /usr/local/bin even though it is in the system path.

       

      Even before "El Capitan" we were discussing ways for the Mac version to behave like the Windows version and use the files installed in the plugin's "bin" directory.

       

       

          if MAC_ENV then
      
              local exportPath = 'export PATH="'
              local toolsPath = LrPathUtils.child(_PLUGIN.path, 'bin"')
              local systemPath = ':$PATH'
              local searchPath = exportPath..toolsPath..systemPath
      --        LrTasks.execute(searchPath) -- this doesn’t work

       

      The script calls this dependency check:

       

      -- Check for Mac dependencies
      function MLProcess.checkDependencies()
          return "exec which dcraw exiftool"
      end

       

      The only way it will work on "El Capitan" is if dcraw and exiftool are installed in /usr/bin. Some users are skilled enough to turn off System Integrity Protection to install the tools but that shouldn't be necessary. Another workaround is to start Lightroom from a shell script that sets the path for that session before launching LR. Here's an example:

       

      LR.command

      export PATH="/Library/Application Support/Adobe/Lightroom/Modules/cr2hdr.lrplugin/bin":$PATH
      /Applications/Adobe\ Lightroom/Adobe\ Lightroom.app/Contents/MacOS/Adobe\ Lightroom

       

      Of course these are just workarounds--how can the system path be set? Is it even possible?

        • 1. Re: Set system path on Mac?
          johnrellis Most Valuable Participant

          I may be missing something obvious, but why not invoke the programs from LrTasks.execute() using a fully qualified path?

           

          local dcRawPath = LrPathUtils.child (_PLUGIN.path, "bin/dcraw")

          LrTasks.execute (dcRawPath .. " " .. commandLineArguments)

          • 2. Re: Set system path on Mac?
            danielafort Level 1

            I left out some important points in my question.

             

            There are three command line tools involved. The main tool is cr2hdr and that is the one that needs to find dcraw and exiftool in order to pass arguments to these programs. I didn't write the plugin but this is how cr2hdr is setup:

             

            -- Return command line for cr2hdr
            function MLProcess.generateCmd(exportSettings, pluginPath, filePath, output, args)
            
                local exec = "cr2hdr"
                local gt = " > "
                local cmd = WIN_ENV and 'start /D "%s\\bin" /B /WAIT /BELOWNORMAL %s.exe%s %s' or 'exec "%s/bin/%s"%s %s'
                local log = '%s%s"%s"'
                local escape = WIN_ENV and '"%s"' or '%s'
            
                return string.format(escape,
                    string.format(log,
                        string.format(cmd,
                            pluginPath,
                            exec,
                            args,
                            filePath
                        ),
                        gt,
                        output)
                )
            end
            

             

             

            So the plugin has no issues communicating with bin/cr2hdr but when it needs to invoke dcraw and exiftool, that's when the Mac searches the system path while Windows looks first to the directory where cr2hdr lives.

            • 3. Re: Set system path on Mac?
              johnrellis Most Valuable Participant

              Got it.  Have your plugin write a temporary script and then invoke the script with LrTasks.execute().  The script would contain:

               

              export PATH=path-to-plugin-bin:$PATH

              command-line-to-invoke-cr2hdr

               

              Your previous attempt to call LrTasks.execute(searchPath) didn't work because it set PATH in the environment of the child process created by LrTasks.execute(), not in the environment of the LR process.  When the child process exited, that change to PATH evaporated.

              • 4. Re: Set system path on Mac?
                johnrellis Most Valuable Participant

                You could also make that script permanent, in the plugin /bin directory, containing:

                 

                export PATH=`dirname $0`:$PATH

                command-line-to-invoke-cr2hdr

                 

                The first line prepends the directory containing the script to PATH.  The second line invokes "cr2hdr".  This may need a little tweaking to handle spaces in the directory, not sure -- I can never remember all the obscure rules for text substitution in shell scripts.

                • 5. Re: Set system path on Mac?
                  danielafort Level 1

                  I was having a tough time trying to figure out how to have the plugin write the text file but in your followup it looks like you're suggesting creating a shell script that will set the path to the current working directory then launch cr2hdr--sort of like what I'm telling users to do when launching Lightroom. Is that right?

                   

                  Your shell script did need some tweaking:

                   

                         PATH=`dirname -- "$0"`:$PATH

                   

                  I'm not quite there yet, but seem to be on the right path.

                  • 6. Re: Set system path on Mac?
                    johnrellis Most Valuable Participant
                    I was having a tough time trying to figure out how to have the plugin write the text file but in your followup it looks like you're suggesting creating a shell script that will set the path to the current working directory then launch cr2hdr--sort of like what I'm telling users to do when launching Lightroom. Is that right?

                    Right.

                    • 7. Re: Set system path on Mac?
                      johnrellis Most Valuable Participant
                      PATH=`dirname -- "$0"`:$PATH

                      I think you need to use "export":

                       

                      export PATH=`dirname "$0"`:$PATH

                       

                      Otherwise, the child process running "cr2hdr" won't inherit the new value of PATH.

                      • 8. Re: Set system path on Mac?
                        danielafort Level 1

                        I found another way of doing this without having to create a shell script. One of our programmers who is working on a lua module offered me another solution. The script makes a variable that includes the call to invoke cr2hdr along with all the command line arguments so the path can be set in that same variable. Here is the code:

                         

                         

                        if MAC_ENV then
                            command = 'export PATH="'..LrPathUtils.child(_PLUGIN.path, 'bin"')..':${PATH} && '..command
                        end
                        result = LrTasks.execute(command)

                         

                         

                        Those double quotes that may look out of place are important because path names could include spaces.

                         

                        By the way this is for an interesting project called Magic Lantern. It is a program that runs on certain models of Canon cameras. The plugin is to work with a feature called dual ISO. Basically it allows you to shoot two ISO bracketed images which is then built into an HDR file in post processing. The Lightroom plugin is a front end to the command line tools that do the work.