jsx script to take selected text and add a new page reference using drop-down list for topic
Hi all,
I'm writing yet another script (I keep thinking up new ways to avoid work)...to speed up the process of creating new page references for an index using an existing list of Topics (a list of Symbols(?)).
Usually, I'd select the text, e.g. Fred's FunShack, go to Index > New Page Reference... click the down arrow to move Fred's FunShack onto topic level 2, click the > arrow next to Symbols and double-click the Topic. Then click OK.

I've made a drop-down list (based on stuff gleaned from the web) that uses the existing Topics (again, 'Symbols'), but as always I'm struggling and going around in circles (slowly learning though). I can't seem to pass the drop-down list selection into the next bit of the script to fill out topic line 1.
Here's what I've managed to cobble together:
#target indesign
var myDoc = app.activeDocument;
var myIndex = myDoc.indexes[0];
var myTopics = myIndex.topics.everyItem().name;
var currSelection = app.selection[0];
var myDialog = app.dialogs.add({name:"Choose Category", canCancel:true});
with (myDialog )
with (dialogColumns.add())
with(borderPanels.add())
{
staticTexts.add ('listbox', undefined, myTopics, {multiselect: false});
var Topics = dropdowns.add({stringList:myTopics, selectedIndex:0});
}
if(myDialog.show() == true){
var myString;
alert (myTopics [Topics.selectedIndex])
myDialog.destroy();
}
var currSelection = app.selection[0];
var myTopic = myTopics.selectedIndex;
var currTopic = currSelection.contents;
myTopic.pageReferences.add(currSelection,PageReferenceType.TO_END_OF_STORY);
Can anyone help? I've checked the reference guide https://www.indesignjs.de/extendscriptAPI/indesign-latest/#Topics.html#d1e124842__d1e125032 but it doesn't really make much sense to me because examples in layman's terms aren't given.


