Skip to main content
Gene McCullagh
Known Participant
July 4, 2009
Answered

Making data persistent

  • July 4, 2009
  • 2 replies
  • 2404 views

I suspect the answer to this is staring me in the face but I just don't seem to be able to see it.

If I provide a field in the Plugin Manager for a user to enter info, such as a serial number, how do I make that data persistent? That is, user enters the info and (1) I replace the field with some indication that the info has been entered (2) never ask the user for the info again.

Thanks!

This topic has been closed for replies.
Correct answer john beardsworth

Gene

You do this via LrPrefs. So set up a variable in the top section:

      local prefs = import 'LrPrefs'.prefsForPlugin()

Now we've something to play with. This records a value into the preference:

     prefs.MyVariable = "whatever"

To recall it next time, and guard against it not being there, check it's there

     if prefs.MyVariable then

     staticTextBox.title = prefs.MyVariable
     else
     staticTextBox.title = ' '
     end

Without this process      staticTextBox.title = prefs.MyVariable would fail if the preference didn't exist.

It's worth opening up the LR prefs file to have a look at what's happening

John

2 replies

Gene McCullagh
Known Participant
July 4, 2009

Thanks John! Worked like a charm!

john beardsworth
Community Expert
john beardsworthCommunity ExpertCorrect answer
Community Expert
July 4, 2009

Gene

You do this via LrPrefs. So set up a variable in the top section:

      local prefs = import 'LrPrefs'.prefsForPlugin()

Now we've something to play with. This records a value into the preference:

     prefs.MyVariable = "whatever"

To recall it next time, and guard against it not being there, check it's there

     if prefs.MyVariable then

     staticTextBox.title = prefs.MyVariable
     else
     staticTextBox.title = ' '
     end

Without this process      staticTextBox.title = prefs.MyVariable would fail if the preference didn't exist.

It's worth opening up the LR prefs file to have a look at what's happening

John

Gene McCullagh
Known Participant
July 4, 2009

Thanks John! That's excellent. I looked at preferences but just couldn't noodle it out. Your example cleared the haze!

Do you mean com.adobe.Lightroom2.plist when you say LR Prefs?

john beardsworth
Community Expert
Community Expert
July 4, 2009

Yes, Gene, so you can see exactly how your info is being stored or remove it and test how the plug-in would perform if your plugin was being installed for the first time. Prefs seems to get written to the plist file immediately, so you can hack it with test values, but remember it is rewritten by LR when you exit. It seems incorruptible....

John