1 person found this helpful
Does app.textPreferences.showInvisible = true not work here?
When you have found a menu action you can remember its ID and use menuActions.itemByID() later on to retrieve it. Most action IDs are hard wired, bound to their implementing plugin. Of course there is an exception for dynamically allocated actions, e.g. script actions.
My first attempt following you is to retrieve the action name - that should trigger the internal method to update the whole action state including checked, enabled (not applicable in this case). Of course it failed, would someone please file a bug? The translated versions of strings that you'd use for the comparison are available via app.translateKeyString().
Btw you are using the wrong string - cmd strings are used for command history as seen in the undo menu. Menu strings usually have an ampersand character to indicate the underline / Alt+Key combo in Windows.
$.writeln(app.menuActions.itemByID(0x1d301).name==app.translateKeyString("$ID/Show Hidden Characters"));
$.writeln(app.menuActions.itemByID(0x1d301).name==app.translateKeyString("$ID/Hide Hidden Characters"));
app.translateKeyString("$ID/Show Hidden Characters")
Ergebnis: Verborgene Zeic&hen einblenden
app.translateKeyString("$ID/Hide Hidden Characters")
Ergebnis: &Verborgene Zeichen ausblenden
// failed test
// output should change after invoke
Verborgene Zeichen ausblenden
Verborgene Zeichen ausblenden
As you found command strings, I also had a look at the undo history - it remained empty.
Probably the setting is not persisted in the document any more, someone should have removed the command strings.
Then I realized that the output of the previous lines around the invoke had changed as it was expected originally. And I had not touched the menu since restart … but I had activated the application.
One can do that with scripting too - app.activate();
A couple of restarts later this is definitely leading somewhere.
Regarding the command, I also had a second look with a debug build of InDesign: the command is still executed, but there is a flag that binds its undo to the previous command - left as an exercise to verify.
Hmm. It is stored in the persistent document preferences in a structure internally called kDocWorkspaceBoss / ITextOptions, thus should also be exposed for scripting. Back to scripting: set a breakpoint, browse thru tons of document sub-objects, and here we are:
Edit: when comparing the strings, you also have to strip the extra ampersand.
I thank you! That does work!
Dirk, I use the itemByID() method in my second script, but was unsure if the ID numbers would change based on other users creating custom menu items... and also I'm fetching the ID based on what you are now telling me is the wrong string. I am usually using Windows, but in this instance am using Mac, so I wasn't sure if I would see the ampersand in the strings.
You did a lot of digging and found more about the cause (not activating the app), so I thank you heartily. I am now getting the desired result and have a bit of insight into what I need to do for the nearly identical function I'm working on for showing hidden text threads (which still relies on menuAction).
Kevin, that's why I shared a bit more than the final conclusion.
For completeness sake, I just had a look at menu strings - those localizations come really handy! In the SDK there is a function to remove "accelerator" characters, and it has a comment that japanese menu strings also use other characters. It was not specified which, and the strip method is not exposed for scripting.