Reputation: 30164
I am trying to script InDesign using ExtendScript. I want the script to cut the selected text, insert a footnote and paste the text into the footnote body. What I have tried:
function makeFootnoteOfSelection(){
var fnText = app.activeDocument.selection[0];
// this should actually clone the selected text, not reference it, because the next statement zaps it from memory
app.activeDocument.selection[0].remove(); // works
var fNote = app.activeDocument.selection[0].footnotes.add(); // works, adds an empty footnote with a reference
fNote.contents = fnText.contents;
// this replaces the reference number, I was hoping to retain it and just add the text
// fNote.contents += fnText.contents; also replaces the reference number
}
Upvotes: 1
Views: 2210
Reputation: 956
InDesign CS5:
function makeFootnoteOfSelection(){
// Reference the selection
var fnText = app.activeDocument.selection[0];
// Add an empty footnote where the selected text is
var fNote = app.activeDocument.selection[0].footnotes.add();
// Move the selected text at the end of the empty footnote
fnText.move(LocationOptions.AFTER, fNote.insertionPoints[-1]);
}
InDesign CS4:
function makeFootnoteOfSelection(){
// Reference the selection
var fnText = app.activeDocument.selection[0];
// Position of the text end
var endPoint = fnText.length - 1;
// Add an empty footnote where the selected text is
var fNote = app.activeDocument.selection[0].footnotes.add();
// Duplicate the selected text at the end of the empty footnote
fnText.duplicate(LocationOptions.AFTER, fNote.insertionPoints[-1]);
// Delete the old Text
fnText.characters.itemByRange(0, endPoint).contents = "";
}
Upvotes: 5