• Global community
    • Language:
      • Deutsch
      • English
      • Español
      • Français
      • Português
  • 日本語コミュニティ
    Dedicated community for Japanese speakers
  • 한국 커뮤니티
    Dedicated community for Korean speakers
Exit
0

Targeting Select All menu language independent

Community Expert ,
Mar 13, 2017 Mar 13, 2017

Copy link to clipboard

Copied

I have a script that adds a menu under the Select All menu.

But I can not target the menu language independent.

I tried "Select_All", "SelectAll' and even "Select All" but it does not work in other languages.
I'm using a Dutch install. When I insert 'Clear' it does add under 'Wissen' in the Dutch version (Wissen=Clear)

Now I'm using this:

var fileMenu = app.menus.item("$ID/Main").submenus.item("$ID/&Edit");

var refItem = fileMenu.menuItems.item("Alles selecteren");

Alles Selecteren is the Dutch entry for Select All, but I want to make this work in any language.

Does anyone know what to target as $ID here?

Thanks!

TOPICS
Scripting

Views

727

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines

correct answers 1 Correct answer

Community Expert , Mar 13, 2017 Mar 13, 2017

Hi Frans,

Use: $ID/Select &All

Why?

var title = app.menus.item("$ID/Main").

submenus.item("$ID/&Edit").

menuItems.item("Alles selecteren").

title;

app.findKeyStrings(title);

// $ID/Select &All

Best look after the title of a menu item for feeding a special method that comes with app.

The name could be not reliable enough.

Regards,
Uwe

Votes

Translate

Translate
Community Expert ,
Mar 13, 2017 Mar 13, 2017

Copy link to clipboard

Copied

Hi Frans,

Use: $ID/Select &All

Why?

var title = app.menus.item("$ID/Main").

submenus.item("$ID/&Edit").

menuItems.item("Alles selecteren").

title;

app.findKeyStrings(title);

// $ID/Select &All

Best look after the title of a menu item for feeding a special method that comes with app.

The name could be not reliable enough.

Regards,
Uwe

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Expert ,
Mar 13, 2017 Mar 13, 2017

Copy link to clipboard

Copied

Thanks Uwe!

The 'why': I reused part od a script I know works (it set a var as menu title used later).

I am no scriptet, just making little steps here 😉

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Expert ,
Mar 13, 2017 Mar 13, 2017

Copy link to clipboard

Copied

Hi Frans,

you are welcome.

As you know I am working with the German version of InDesign.
My customers could work in virtually all localized versions.

So I always try to find the string that works for all if I have to work with menu items and scripting.

app.findKeyStrings()

will produce the ones.
If there is one.

And sometimes it produces two or more strings.

Then you have to test all one after another to find the appropriate one.

In my German version of InDesign I could ask the menu its name or title.

var name =

app.menus.item("$ID/Main").

submenus.item("$ID/&Edit").

menuItems.item("Alles auswählen").name;

var name =

app.menus.item("$ID/Main").

submenus.item("$ID/&Edit").

menuItems.item("Alles auswählen").title;

Returned are

name : "Alles auswählen"

title : "Alles ausw&ählen"

If I run:

app.findKeyStrings("Alles auswählen");

nothing will returned.

Wheras if I run:

app.findKeyStrings("Alles ausw&ählen");

$ID/Select &All will returned.

Regards,
Uwe

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Expert ,
Mar 13, 2017 Mar 13, 2017

Copy link to clipboard

Copied

Thanks Uwe!

I'm still finding my way in Javascript...

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Expert ,
Mar 14, 2017 Mar 14, 2017

Copy link to clipboard

Copied

Uwe, I I may bother you one more time:

Adding a script to a menu works when using the local language:

var fileMenu = app.menus.item("$ID/Main").submenus.item("$ID/&Object").submenus.item("$ID/InteractiveContextMenu");

var refItem = fileMenu.menuItems.item("Tabvolgorde instellen...");

It does NOT work when using the independent menu-item:

var fileMenu = app.menus.item("$ID/Main").submenus.item("$ID/&Object").submenus.item("$ID/InteractiveContextMenu");

var refItem = fileMenu.menuItems.item("$ID/SetTabOrder");

I'm out of my comfort zone here... 😉

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Expert ,
Mar 14, 2017 Mar 14, 2017

Copy link to clipboard

Copied

I got the menuID by number for SetTabOrder, which should be 83469. Can not make that work either... 😞

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Expert ,
Mar 14, 2017 Mar 14, 2017

Copy link to clipboard

Copied

Got it!

This worked:

var refItem = fileMenu.menuItems.itemByID(83469);

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Expert ,
Mar 14, 2017 Mar 14, 2017

Copy link to clipboard

Copied

Hi Frans,

glad you found your way around.

BTW: The locale independent name of that menuItem is:

$ID/$$$/Menu/SetTabOrder


Regards,
Uwe

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Expert ,
Mar 14, 2017 Mar 14, 2017

Copy link to clipboard

Copied

Yes, still one thing that I can not get to work, and that is targeting Show/Hide Hidden Characters, That should be

fileMenu.menuItems.itemByID(119553);

But that keeps coming back as error.

A well, another night with little sleep I guess  😉

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Expert ,
Mar 14, 2017 Mar 14, 2017

Copy link to clipboard

Copied

Hi Frans,

to make a menu item work, you have to check if it is perhaps grayed out under special circumstances.
Or if ir exists at all. In the moment you are asking.

For example: The functionlity behind "Set Tab Order…" is not available, if there is no or only one form field item positioned on the active page. It is grayed out.

For a menuItem you could look into the values of some important properties:

isValid

enabled

checked

isValid is the most important one.

If isValid is true, the menuItem exists in the moment you are calling isValid.

enabled means it is ready to use.

Not grayed out. See above where I did my little example.

checked could be true, false or not appropriate.

Some of the menuItems are simply not checkable.

And some change their names if you invoke their associated menu action:

"Show/Hide Hidden Characters" is one of them.

So it could be, that "Show Hidden Characters" is enabled and isValid.

Or "Hide Hidden Characters" is enabled and isValid. Both cannot be isValid at the same time.
And both states of that menuItem can never be "checked".

It can only change its name every time you invoke it.

The two strings are:

$ID/Hide Hidden Characters

$ID/Show Hidden Characters

Regards,
Uwe

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Expert ,
Mar 14, 2017 Mar 14, 2017

Copy link to clipboard

Copied

Laubender  schreef

And some change their names if you invoke their associated menu action:

"Show/Hide Hidden Characters" is one of them.

So it could be, that "Show Hidden Characters" is enabled and isValid.

Or "Hide Hidden Characters" is enabled and isValid. Both cannot be isValid at the same time.
And both states of that menuItem can never be "checked".

It can only change its name every time you invoke it.

The two strings are:

$ID/Hide Hidden Characters

$ID/Show Hidden Characters

Strange enough that is NOT the case. It works fine in the Dutch version nl_NL, wether it is Show or Hidden, it attaches itself after the menu. Just like the ShowOverrides script did.
However, it results in an error in the en_US language (or other)...

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Expert ,
Mar 14, 2017 Mar 14, 2017

Copy link to clipboard

Copied

AH!

Geez... must be tired:

I used: $ID&Text

Should be: $ID&Type

Then fileMenu.menuItems.itemByID(119553);  works!

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Expert ,
Mar 14, 2017 Mar 14, 2017

Copy link to clipboard

Copied

Hi Frans,

after re-reading your posts before I now saw it as well.

The submenu you want to address is submenus.item("$ID/&Type").

Now you get the menu item by its ID number.

Very practically because this item has two different names and only one distinct ID number.

Usually I would hesitate to rely on a specific ID numbr of a menu item.

It remains to be seen if this ID number is always the same with different InDesign versions.

In the meanwhile I tested a bit by addressing the menu item. Whether it's in the one or in the other state. By ID or by name.

To my surprise I had a bit trouble to get the right state—"Hide Hidden Characters" vs. "Show Hidden Characters".

Sometimes it seems that InDesign returned the opposite what I was seeing in the UI.

I ran the following snippet a couple of times with inconsistent results. Inconsistent results occured if I changed the menu from one state to the other in the UI using my trackpad. But I could provoke the problem not very often.

Here the code:

var result = ["BEFORE/AFTER should be different:"];

var showHideHiddenChars =

    app.menus.item("$ID/Main").

    submenus.item("$ID/&Type").

    menuItems.itemByID(119553);

result[result.length++] = "BEFORE"+": "+showHideHiddenChars.name;

result[result.length++] = "showHideHiddenChars.associatedMenuAction.invoke();";

showHideHiddenChars.associatedMenuAction.invoke();

result[result.length++] = "AFTER"+": "+showHideHiddenChars.name;

alert(result.join("\r"));

$.writeln(result.join("\r")+"\r"+"*****");

By invoking the menu item, its name should change.

From e.g. "Show Hidden Characters" (German: "Verborgene Zeichen einblenden") to "Hide Hidden Characters" (German: "Verborgene Zeichen ausblenden") and reverse. Usually it did. Here a good result:

3-associatedMenuAction.invoke.png

But it also happened, that invoking the menu returned not a changed name.
Even so that a different name was visible with the UI and the function worked as expected.

Sometimes after I changed the menu item in the UI with the trackpad of my MacBook Pro.
But not always.

1-associatedMenuAction.invoke.png

Tested with InDesign CS6 8.1.0 on Mac OSX 10.6.8.

Regards,
Uwe

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Expert ,
Mar 14, 2017 Mar 14, 2017

Copy link to clipboard

Copied

Thanks Uwe.

Yes, Text/Type... it was staring my right in the face but I missed it 😞

All is working now for me.

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Expert ,
Mar 19, 2017 Mar 19, 2017

Copy link to clipboard

Copied

LATEST

One more, that I can not solve:

I have the first basic PD script from Keith Gilbert, but that saves the files and folders in the same dir as the source document.

I would OR like to select the folder they files get saved in OR to create a parent folder.

I tried "new Folder (myDocBaseName + "HTML5 Export")" somewhere in the script to create a new parent folder in the same dir but that failed.

Any help is very, very welcome.

This is the source from Keith:

// Check to see whether any InDesign documents are open.

  // If no documents are open, display an error message.

  if (app.documents.length > 0) {

  var myDoc = app.activeDocument;

  // Build the filename

  var myDocName = decodeURI(myDoc.fullName);

  var myDocBaseName = myDocName.substring(0, myDocName.lastIndexOf("."));

  // Export the page to FXL HTML

  with (myDoc.htmlFXLExportPreferences) {

  epubPageRangeFormat = PageRangeFormat.EXPORT_ALL_PAGES

// epubPageRangeFormat = PageRangeFormat.EXPORT_PAGE_RANGE

// epubPageRange = "1-2";

  }

  myDoc.exportFile(ExportFormat.HTMLFXL, new File(myDocBaseName + ".html"), true);

alert("De HTML5-export is klaar!");

    }

  else {

  // No documents are open, so display an error message.

  alert("Er zijn geen documenten geopend!")

}

}  

   };

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines