7 Replies Latest reply on Nov 12, 2015 10:46 AM by johnrellis

    How to remove entries from LrPrefs

    timkognito

      Hi,

       

      how can I remove entries (key/value) from the table returned by LrPrefs.prefsForPlugin()?

      I tried several things (like setting value to nil, removing the plugin) but the entries are still present. Now the prefs-table is poluted with entries from testing.

       

      Kind regards,

      Tim

        • 1. Re: How to remove entries from LrPrefs
          johnrellis Most Valuable Participant
          like setting value to nil

          Hmm, that's always worked for me.  Perhaps you can post a small sample script showing how it's not working for you?

           

          Here's the typescript from a session showing the results of prefsForPlugin(), adding a new key "test", showing the key is in the preferences table, then deleting the key by doing "prefsForPlugin().test = nil", and then showing that "test" is no longer in the preferences table:

           

          15/11/12 10:34:10com.johnrellis.debugscript TRACE Eval: LrPrefs.prefsForPlugin()
          {--table: 1
              __validate = function: 0x6000020828a0, 
              [{--table: 2
                  _name = "kWeakObservationConditionsKey"}] = table: 0x60000606a400, 
              ["< contents >"] = {--table: 3
                  debugScriptFilename = "/Users/john/Desktop/plugins/test.lrdevplugin/eval.lua", 
                  debugClearPrefs = true, 
                  debugInvokeEditor = true, 
                  debugEvaluate = "targetPhoto:getDevelopSnapshots()", 
                  debugLogWindow = true, 
                  debugScriptOpenDebugWindow = true, 
                  debugEditorCommandLine = "\"/Applications/Sublime Text 2.app/Contents/SharedSupport/bin/subl\" \"{file}:{line}\"", 
                  debugReloadScripts = true, 
                  debugScriptShowNewGlobals = true}, 
              [{--table: 4
                  _name = "kPersistentObservationConditionsKey"}] = {}}
          
          
          15/11/12 10:34:44com.johnrellis.debugscript TRACE Eval: LrPrefs.prefsForPlugin().test = "Hello world"
          
          
          15/11/12 10:34:55com.johnrellis.debugscript TRACE Eval: LrPrefs.prefsForPlugin()
          {--table: 1
              __validate = function: 0x6000020828a0, 
              [{--table: 2
                  _name = "kWeakObservationConditionsKey"}] = table: 0x60000606a400, 
              ["< contents >"] = {--table: 3
                  debugScriptFilename = "/Users/john/Desktop/plugins/test.lrdevplugin/eval.lua", 
                  debugClearPrefs = true, 
                  debugInvokeEditor = true, 
                  debugEvaluate = "targetPhoto:getDevelopSnapshots()", 
                  debugLogWindow = true, 
                  debugScriptOpenDebugWindow = true, 
                  test = "Hello world", 
                  debugEditorCommandLine = "\"/Applications/Sublime Text 2.app/Contents/SharedSupport/bin/subl\" \"{file}:{line}\"", 
                  debugReloadScripts = true, 
                  debugScriptShowNewGlobals = true}, 
              [{--table: 4
                  _name = "kPersistentObservationConditionsKey"}] = {}}
          
          
          15/11/12 10:35:01com.johnrellis.debugscript TRACE Eval: LrPrefs.prefsForPlugin().test
          "Hello world"
          
          
          15/11/12 10:35:17com.johnrellis.debugscript TRACE Eval: LrPrefs.prefsForPlugin().test = nil
          
          
          15/11/12 10:35:34com.johnrellis.debugscript TRACE Eval: LrPrefs.prefsForPlugin().test
          nil
          
          
          15/11/12 10:35:39com.johnrellis.debugscript TRACE Eval: LrPrefs.prefsForPlugin()
          {--table: 1
              __validate = function: 0x6000020828a0, 
              [{--table: 2
                  _name = "kWeakObservationConditionsKey"}] = table: 0x60000606a400, 
              ["< contents >"] = {--table: 3
                  debugScriptFilename = "/Users/john/Desktop/plugins/test.lrdevplugin/eval.lua", 
                  debugClearPrefs = true, 
                  debugInvokeEditor = true, 
                  debugEvaluate = "targetPhoto:getDevelopSnapshots()", 
                  debugLogWindow = true, 
                  debugScriptOpenDebugWindow = true, 
                  debugEditorCommandLine = "\"/Applications/Sublime Text 2.app/Contents/SharedSupport/bin/subl\" \"{file}:{line}\"", 
                  debugReloadScripts = true, 
                  debugScriptShowNewGlobals = true}, 
              [{--table: 4
                  _name = "kPersistentObservationConditionsKey"}] = {}}
          
          
          • 2. Re: How to remove entries from LrPrefs
            johnrellis Most Valuable Participant

            [My previously reply is being "moderated" by the silly forum software and will eventually show up.  But here's the reply without the long typescript that triggered the moderation.]

            like setting value to nil

            Hmm, that's always worked for me.  Perhaps you can post a small sample script showing how it's not working for you?

             

            Here's the typescript from a session showing the results of prefsForPlugin(), adding a new key "test", showing the key is in the preferences table, then deleting the key by doing "prefsForPlugin().test = nil", and then showing that "test" is no longer in the preferences table:

            • 3. Re: How to remove entries from LrPrefs
              timkognito Level 1

              Hi John,

               

              sorry, I don't know what went wrong. Now it works (prefsForPlugin().test= nil, and even prefsForPlugin["test"]=nil).

              Maybe it was a little bit late ...

               

              Many thanks,

              Tim

              • 4. Re: How to remove entries from LrPrefs
                johnrellis Most Valuable Participant

                Glad it's working now. 

                prefsForPlugin().test= nil, and even prefsForPlugin["test"]=nil

                Note that the two expressions are exactly equivalent:  a.b is syntactic sugar for a["b"].