Solved:
var
myDoc = app.activeDocument,
mStory = app.selection[0].texts[0].parentStory,
mEndNotes = myDoc.textFrames.add( {name:”EndNotes”} ),
k, len, cIP, currPara, currFoot, mMarkers;
app.findGrepPreferences = app.changeGrepPreferences = null;
//———————————————
// edit doc.footnoteOption here
with (myDoc.footnoteOptions)
{
showPrefixSuffix = FootnotePrefixSuffix.PREFIX_SUFFIX_BOTH;
prefix = “[“;
suffix = “]”;
separatorText = “”;
markerPositioning = FootnoteMarkerPositioning.NORMAL_MARKER;
}
//————————————————————
// move endnotes to a separate textFrame
for (k=mStory.paragraphs.length – 1; k >=0; k–)
{
if (mStory.paragraphs[k].contents.search(/^\*+/) == 0)
{
currPara = mStory.paragraphs[k].move(LocationOptions.AT_BEGINNING, mEndNotes.parentStory);
currPara.words[0].remove();
}
}
//————————————–
// create footnote markers
app.findGrepPreferences.findWhat = “*+”;
mMarkers = mStory.findGrep();
len = mMarkers.length;
while (len–>0) {
cIP = mMarkers[len].insertionPoints[0].index;
mMarkers[len].remove();
mStory.footnotes.add( LocationOptions.AFTER, mStory.insertionPoints[cIP] );
}
//——————————————————-
// fill footnote contents with proper text
for (k=0; k < mStory.footnotes.length; k++) {
currFoot = mStory.footnotes[k];
mEndNotes.paragraphs[0].texts[0].move(LocationOptions.AT_END, currFoot.texts[0]);
if (mStory.footnotes[k].characters[-1].contents == “\r”) mStory.footnotes[k].characters[-1].remove();
}
mEndNotes.remove();