4 Replies Latest reply on Sep 12, 2014 4:08 PM by areohbee

    How do I make the plugin run automatically when a photo is imported?

    psaha84

      I am trying to write a new plugin where the metadata will be automatically added to the photo when I import the photo in the Lightroom.

      How do I make the plugin run automatically when a photo is imported?

       

      Thanks for  your help!

       

      Regards,

      Prosenjit

        • 1. Re: How do I make the plugin run automatically when a photo is imported?
          johnrellis Most Valuable Participant

          There's no SDK mechanism that allows a plugin to be directly triggered by an import.   The best you can do is to scan the catalog in background periodically for new imports.  Rob Cole, an active forum participant, has a number of plugins that do this, so he might be able to advise you on the best methods of doing this.

           

          I assume you're aware that Lightroom allows you set to set metadata for imported photos?  Lightroom Help | Specify import options

          • 2. Re: How do I make the plugin run automatically when a photo is imported?
            areohbee Level 5

            Assuming your plugin won't be doing the importing, then

             

            * would it be possible to require metadata or something to make it easier for your plugin to detect imported photos?

             

            For example, could you ask users to assign a keyword "Imported" upon import, then you only have to look at photos with that keyword, and when you find them, clear the keyword and process..

             

            Obviously, you can (continuously) go through every photo in the catalog, and see if it was there before, but it's kinda cpu intensive..

             

            Be aware that Lr does NOT stop background tasks when you reload the plugin, so they can gang up. - so make sure you have a shutdown module which sets a global shutdown variable, and check that variable in your background tasks - if set, return from the task.

             

            Likewise, make sure background tasks are stopped if there is an error (use function context cleanup handler).

             

            Without such precautions, background tasks can really be problematic..

             

            PS - A great way to have a background task (if LR 5+ can be a requirement) is to use a floating dialog, which represents your background task - when dialog box disappears, so does your background task..

             

            Rob

            • 3. Re: How do I make the plugin run automatically when a photo is imported?
              psaha84 Level 1

              Thanks for your reply

               

              According to you I think user has to manually assign a keyword "imported" upon import. I do not want this.

              What I want is, when I import a photo in Lightroom the plugin will run and assign the metadata.

               

              One more question, How do I save the custom metadata with the image file?

              Lightroom 5 has the limitation, plugin  cannot link the custom metadata fields to XMP file or save them with image file.

              So, is there any alternative way to save the custom metadata?

              • 4. Re: How do I make the plugin run automatically when a photo is imported?
                areohbee Level 5

                psaha84 wrote:

                 

                What I want is, when I import a photo in Lightroom the plugin will run and assign the metadata.

                As John said, there is no mechanism to receive notification of import. The likely recourse is continuous polling (unless you get very creative..).

                 

                You can try optimizing. e.g.: every second (or less), see if the count has changed, if it's gone up, something's been imported, if not then probably not (check anyway once in a while..).

                 

                psaha84 wrote:

                 

                How do I save the custom metadata with the image file?

                 

                Lightroom 5 has the limitation, plugin  cannot link the custom metadata fields to XMP file or save them with image file.

                So, is there any alternative way to save the custom metadata?

                Yeah: Lightroom won't save custom metadata in xmp, nor read it if it's there, so you are pretty much on your own - you can save in a file, but if you save as non-standard sidecar Lr won't attend to it like it will jpg or xmp sidecar. For that reason it's often better to save in a separate dedicated location. You can save in image file itself, e.g. using exiftool if raw file, but that would make me nervous, and of course you'd have to have the logic to read it somewhere too..

                 

                Good luck,

                Rob