Copy link to clipboard
Copied
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?
And of course the answer comes to me five minutes after posting: just use the `properties` property!
var initialPreferences = app.findTextPreferences.properties;
app.findTextPreferences = NothingEnum.NOTHING;
// do rest of stuff here
app.findTextPreferences.properties = initialPreferences;
So simple. 🤦🏼
.properties will catch most stuff, but it's only a shallow copy. For those properties that are themselves objects, IIRC it won't work.
FWIW, the way I deal with it is this https://www.id-extras.com/tidy-up-after-yourself/
(written 11 years ago, but still works!)
Copy link to clipboard
Copied
And of course the answer comes to me five minutes after posting: just use the `properties` property!
var initialPreferences = app.findTextPreferences.properties;
app.findTextPreferences = NothingEnum.NOTHING;
// do rest of stuff here
app.findTextPreferences.properties = initialPreferences;
So simple. 🤦🏼
Copy link to clipboard
Copied
.properties will catch most stuff, but it's only a shallow copy. For those properties that are themselves objects, IIRC it won't work.
FWIW, the way I deal with it is this https://www.id-extras.com/tidy-up-after-yourself/
(written 11 years ago, but still works!)
Copy link to clipboard
Copied
Ahaaa! There’s a whole method for doing just that – I would never have found that (because I wasn’t expecting it to exist). That sounds a lot more reliable. Thank you!
Copy link to clipboard
Copied
Thanks @TᴀW, I didn't know about those methods. Nice!
- Mark
Copy link to clipboard
Copied
There are load / save FindChangeQuery:
https://www.indesignjs.de/extendscriptAPI/indesign-latest/#Application.html#d1e42291__d1e47679
Copy link to clipboard
Copied
🤔
For completeness sake, I think this does not preserve the previous user choice of the "Query" dropdown …
Looking at the OM, I haven't found a way to get that value.
Find more inspiration, events, and resources on the new Adobe Community
Explore Now