Skip to main content
Inspiring
February 23, 2018
Question

Add script to context menu on paragraph or character styles panel?

  • February 23, 2018
  • 5 replies
  • 2897 views

Does anybody know, if there is a chance, to add a script to the context menu, when selecting a paragraph or character style with the right button of the mouse? And then work with the selected style inside the script?

Thanks

Tobias

This topic has been closed for replies.

5 replies

Adobe Expert
January 7, 2020

Hi Tobias,

right! Did further tests and came to the conclusion that often the update of the menu items is OK and right in time.

But sometimes the update is only done when I open the context menu. Unfortunately this cannot be simulated or done by DOM scripting. So in the end I think you have to drop the idea altogether.

 

FWIW: Something similar was discussed over at hilfdirselbst.ch:

 

In Absatzformatpalette ausgewählte Absatzformate ermitteln
Martin Fischer, 13. Dez 2019

https://www.hilfdirselbst.ch/gforum/gforum.cgi?post=573264#573264

 

I came to the same conclusion there:

There is no reliable way to read out actual data from the context menu of the Paragraph Panel.

 

Regards,
Uwe Laubender

( ACP )

Adobe Expert
December 23, 2019

Hi Tobias,

after some more tests I find that the context menu "$ID/RtMenuStyleListItem" ("Textformatliste-Kontextmenü") is not updated as often as it should be. Rerunning the same code several times when different documents were active did not update the results when I tried to read out the different menuItems and their names or titles.

 

Hope, that "$ID/ParaStyleControlPanelPopup" ("Absatzformat-Steuerungsbedienfeldmenü") is more reliable.

Maybe we have the chance to detect with menuItems named "$ID/Duplicate Style..." and "$ID/Duplicate Styles" if only one style is selected, if two or more styles are selected or if actually no style is selected.

 

One could exploit properties isValid and enabled of both menuItems.

 

Regards,
Uwe Laubender

( ACP )

Inspiring
January 4, 2020

Thanks Uwe for your suggestions!

 

The deeper we get into this, the more it comes out, that there is no satisfiable solution for my use case via scripting. I think, I have to quit this try.

 

Thanks, Tobias

Adobe Expert
December 22, 2019

Hi Tobias,

that may help you:

 

If just one sigle paragraph style is selected in the Paragraph Styles Panel adding a temp text frame to the document with some contents will reveal what exactly is selected. The same goes for a selected character style.

 

But this is not as much unique as you might think.

If a paragraph style group is selected the temp frame's text will reflect the last selected style.

The same goes with the situation where the user did not select a style or a style group.

 

Regards,
Uwe Laubender

( ACP )

Adobe Expert
February 27, 2018

Hi Tobias,

I'm not sure what exact context menu you are looking for.

Is it this one:

Or is it that one:

Or something else entirely?

To get the selected paragraph style in the Paragraph Style panel when no text is selected by the user, just add a new text frame to the document and see what paragraph style is applied to the first insertion point of its parent story.

Regards,
Uwe

Inspiring
February 27, 2018

Hej Uwe,

It's the latter one: $ID/ParaStyleControlPanelPopup

I had in mind to get the paragraph style, which I right click on. That's not necessarily the one, which is selected:

Hm. I now think this can't be done with scripting ...

Thanks

Tobias

Adobe Expert
February 27, 2018

Ah yes, I see now what you are looking for. If the menu is really "$ID/ParaStyleControlPanelPopup" you can get access to all the menuElements of the popup and retrieve the name of the paragraph style. But I'm in doubt if "$ID/ParaStyleControlPanelPopup" is the right one.

 

If I run the script below in a situation I am showing here:

 

 

I do not get "[Einf. Abs.]" bearbeiten… and so on. So I think, we still have to search for the right menu.

See result below:

 

var menuName = "$ID/ParaStyleControlPanelPopup";
var menuElements = app.menus.itemByName(menuName).menuElements.everyItem().getElements();

for( var n=0; n<menuElements.length; n++ )
{
    if(menuElements[n].constructor.name == "MenuSeparator"){ continue };
    $.writeln( n+"\t"+menuElements[n].title );
};

/*

0    Neues Absatzformat...
1    Format duplizieren...
2    Format löschen...
4    Format neu definieren
6    Formatoptionen...
8    Abweichungen löschen
9    Aufzählungszeichen und Nummerierung von "[Einf. Abs.]" in Text konvertieren
10    Verknüpfung mit Format aufheben
12    Absatzformate laden...
13    Alle Textformate laden...

*/

 

Regards,
Uwe

 

REPLY EDITED: Had to edit this post because the script code was not transferred to the new forum without errors.

Trevor:
Brainiac
February 26, 2018

Hi

app.menus.everyItem().name.join('\n').match(/[^\n]+Context Menu/g).join('\n')

Will give you a list of the context menus which I thing is what you are after.

app.menus.itemByName('Text Style List Context Menu').menuItems.everyItem().name.join('\n')

Gives

Edit "Paragraph Style 1"...

Duplicate Style...

Delete Style

Redefine Style

Apply "Paragraph Style 1"

Apply "Paragraph Style 2", Clear Overrides

Apply "^1", Clear Character Styles

Apply "^1", Clear All

Apply "^1" then Next Style

Apply "^1" then Next Style, Clear Overrides

Apply "^1" then Next Style, Clear Character Styles

Apply "^1" then Next Style, Clear All

Convert "Paragraph Style 1" Bullets and Numbering to Text

New Paragraph Style...

Style Group Options...

Duplicate Group

Delete Group...

Copy to Group...

New Group from Styles...

This is obviously dynamically generated and further filtered so you probably would have I tough time messing around with it.

In  German etc. you will need to do a bit of translating.

Have fun.

Trevor

P.s. I'm not sure that this is the correct menu but it's a possible starting point

Inspiring
February 26, 2018

Wow – thanks, Trevor! This is a very good starting point ...

Thanks

Tobias

Colin Flashman
Adobe Expert
February 27, 2018

Peter Kahrel has some really good information on his site about this, and the links in the article are quite helpful as well:

Show InDesign's menu actions | Peter Kahrel

Perhaps have a look at some startup scripts in the public domain, like the addpathoperationstolayoutmenu by Ole Kvern: InDesign Scripting: Baby Steps  (it's at the end of his article which is also a great read too).

If the answer wasn't in my post, perhaps it might be on my blog at colecandoo!