I finetuned the snippet above a bit further. In some cases the context menu will be activated (right mouseclick) from a style that is not currently selected. In thoses cases the example above doesn't give the correct information. In order to avoid this I am now applying the paragraph style of the current context menu to an intermediate textframe. The snippet below is placed inside the EventHandler of my custom context menu item.
var myDoc = app.activeDocument; //store current selection var mySelection = myDoc.selection; //create intermediate textframe var myTextFrame = myDoc.textFrames.add(); myTextFrame.contents = "grab the paraStyle"; myTextFrame.select(); //apply the para style of the context menu to the intermediate text var contextMenu = app.menus.item("Text Style List Context Menu"); //or "$ID/RtMenuStyleListItem" var applyMenuItem = contextMenu.menuItems.itemByID(8488).associatedMenuAction; //Apply "para style for context menu" applyMenuItem.invoke(); //grab the para style of the context menu var myParaStyle = myTextFrame.paragraphs.appliedParagraphStyle; //restore original selection and remove intermediate textframe myDoc.selection = mySelection; myTextFrame.remove();
Again this snippet seems to work fine. I realize this approach will only work for para styles in a Document object and not for default para styles defined in the Application (suggestions to solve this?). A further refinement could be to first check if a para style name is unique, if that is the case the solution of Jongware (see http://forums.adobe.com/message/2861568#2861568) can be used and an intermediate textframe is not required.
I know this is a dirty solution but are there any issues with this approach?