3 Replies Latest reply on Aug 8, 2010 11:59 PM by M. Marinov

    Lightroom plugin auto startup

    M. Marinov

      I'm trying to write something like a statistics plugin for Lightroom. I need the plugin to startup automatically without user interaction (after all I'm collecting statistics which should be an automated process). I have read the API but i didn't find a way to do it. I tried to add executable code in Info.lua but it is limited (it cannot use import so I can not access Lr* but only strings). I tried to use the LrEnablePlugin, LrInitPlugin but they are invoked only when manually loading/reloading the plugin or opening the Plugin Manager. I'm out of ideas, except if there is a more robust way for writing extensions for the core product.

       

      Yet, I didn't find an event system in the API. It's good to know when a photo is edited, imported, rated, etc. I'm thinking of two ways to overcome this - first way is to intercept the functions so that they call a user defined function first (e.g. getAllPhotos to call getAllPhotosCallback first and than the original getAllPhotos) but this counts on the assumption that Lightroom itself uses these functions rather than that they are only interface functions; the other way is to use a publishing service.

       

      Actually the auto start problem is a 'show stopper'. Without overcoming it the whole plugin would be useless.

       

      PS: Sorry for reposting, I have already posted in the general Lightroom forum. I didn't this one exists.

       

      Thanks in advance,

      Marin

        • 1. Re: Lightroom plugin auto startup
          areohbee Level 5

          Toss in a custom metadata item (hide it if you can't use it) and LrInitPlugin will be called when Lightroom first starts up - you can then pretty much do what you want in a background thread - no events but you can poll... Just be aware that catalog write accesses in a background thread can collide with other plugins, I use this for accessing catalog so no problems:

           

          --[[
                  Synopsis:           Catalog access wrapper that distinquishes catalog contention errors from target function errors.
                 
                  Notes:              - Returns immediately upon target function error.
                
                                      - The purpose of this function is so multiple concurrent tasks can access the catalog in succession without error.
                                     
                                      func is catalog with-do function
                                      cat is the catalog object.
                                      p1 is first parameter which may be a function, an action name, or a param table.
                                      p2 is second parameter which will be a function or nil.
                 
                  Returns:            itsAGoOrNot, andWhatever.
          --]]       
          function RcUtils.withCatalogDo( tryCount, func, cat, p1, p2 )
              while( true ) do
                  for i = 1, tryCount do
                      local sts, qual = LrTasks.pcall( func, cat, p1, p2 )
                      if sts then
                          return true, qual
                      elseif RcString.is( qual ) then
                          local found = qual:find( "LrCatalog:with", 1, true ) or 0 -- return position or zero, instead of position or nil.
                          if found == 1 then -- problem reported by with-catalog-do method.
                              local found2 = qual:find( "already inside", 15, true )
                              if found2 then
                                  -- problem is due to catalog access contention.
                                  if RcUtils._debugMode then -- module development debug.
                                      LrDialogs.message( 'cat contention: ' .. RcLua.toString( qual ) )
                                  elseif RcUtils.debugMode then -- log verbose - user app-wide debug mode
                                      RcUtils.logWarning( 'cat contention: ' .. RcLua.toString( qual ) )
                                  else
                                      LrTasks.sleep( math.random( .1, 1 ) ) -- sleep for a half-second or so, then try again.
                                  end
                              else
                                  -- LrDialogs.message( 'not already inside cat: ' .. RcLua.toString( qual ) )
                                  return false, qual
                              end
                          else
                              -- LrDialogs.message( 'not a cat with msg: ' .. RcLua.toString( qual ) )
                              return false, qual
                          end
                      else
                          -- LrDialogs.message( 'bad cat sts, but no msg.' )
                          return false, 'Unknown error occurred accessing catalog.'
                      end
                  end
                  local action = RcUtils.showWarning( "Unable to access catalog.", "Keep Trying", "Give Up" )
                  if action == 'ok' then
                      -- keep trying
                      -- LrDialogs.message( "Will try again." )
                  else
                      -- assert( action == 'cancel', "unexpected error action: " .. RcLua.toString( action )  )
                      -- LrDialogs.message( "Gave up trying to access catalog." )
                      return false, "Gave up trying to access catalog."
                  end
              end
              -- RcUtils.logError( "Unable to access catalog." ) - let this be done in calling context.
              -- LrDialogs.message( LOC( "$$$/X=Unable to access catalog after ^1 tries.", tryCount ) )
              return false, LOC( "$$$/X=Unable to access catalog." )
          end

          • 2. Re: Lightroom plugin auto startup
            M. Marinov Level 1

            Thanks for the immediate reply, I'll be back tomorrow.

            • 3. Re: Lightroom plugin auto startup
              M. Marinov Level 1

              Autostart problem solved, thanks