Storing an immutable copy of an internal application object (e.g., FindTextPreference)
I have a script that I often use repeatedly while using the Find/Change dialogue in the UI.
The script makes some text substitutions in the document, and because it uses the application’s FindTextPreferences for this, the Find/Change dialogue is also updated in the UI. This is kind of annoying, because then I have to reset it and enter the search criteria I was using every time the script is run.
I figured this would be easy to fix; just do this:
var initialPreferences = app.findTextPreferences;
app.findTextPreferences = NothingEnum.NOTHING;
// do rest of stuff here
app.findTextPreferences = initialPreferences;
Unfortunately, that doesn’t work – the variable value appears to be assigned by reference, so every time I change anything app.findTextPreferences, the variable is also updated. The FindTextPreference class doesn’t have duplicate() method.
Is there a way to store an immutable ‘snapshot’ of the preferences that I can then use to reset the Find/Change dialogue’s state when the script is done?
Moreover, is it even possible to assign the preferences like that? The API docs indicate that you can (findTextPreferences is listed as read/write, expecting a FindTextPreference object or NothingEnum.NOTHING), but when I try to assign it, I get an error 30477:
> Invalid value for set property 'findTextPreferences'. Expected NothingEnum enumerator, but received FindTextPreference.
So is it not even possible to set it like that?
