// Endnoteletters2numbers.jsx // changes endnote letters to numbers // Presuppositions: when importing from Word, make sure // Show Import options is on. Next make sure that a new style // Endnote Reference is made for endnote references (this is standard). // The endnote numbers in the text must have the // character style chosen in the dialog displayed at starting the script. // The Endnote text must have the paragraph style chosen in // the dialog displayed at starting the script. // The endnote separator must be the character specified in // the dialog displayed at starting the script and must not // be used in paragraphs in endnotes that have no endnote number. // Made by Teus de Jong; last version August 28, 2005 var doendnotes = true; endnotereferencestyle = 'Endnote Reference'; endnotetextstyle = 'Endnote Text'; endnoteseparator = '^t'; // tab if (!doDisplayDialog()){exit()} u = undefined; app.findPreferences = app.changePreferences = null; notes = app.activeDocument.search(u, u, u, u, {appliedCharacterStyle: endnotereferencestyle}); for (i = notes.length-1; i > -1; i--){ notes[i].contents = letterstonumbers(notes[i].contents); } app.findPreferences = null; if (!doendnotes){exit()} notetexts = app.activeDocument.search('^p', u, u, u, {appliedParagraphStyle: endnotetextstyle}); for (i = notetexts.length-1; i > -1; i--){ if (notetexts[i].paragraphs[0].contents.indexOf(endnoteseparator) == -1) {continue} try{ notetexts[i].paragraphs[0].words[0].contents = letterstonumbers(notetexts[i].paragraphs[0].words[0].contents); } catch (e) {} } app.findPreferences = null; function letterstonumbers(s){ var i; var havepoint = false; x = 0; if (s.indexOf('.') == s.length - 1){ s = s.split('.')[0]; havepoint = true; } if (!checkcontents(s)){ if (havepoint){ s = s+'.'; } return(s); } ln = s.length; for (i = ln-1; i > -1; i--){ multiplier = Math.pow(26, ((ln-1) - i)); x += (s.charCodeAt(i) - 96) * multiplier; } s = x.toString(); if (havepoint){ s = s + '.'; } return(s); } function checkcontents(s){ var i; for (i = 0; i < s.length; i++){ if ((s.charCodeAt(i) < 97) || (s.charCodeAt(i) > 122)){ return(false); } } return(true); } function doDisplayDialog(){ var i; with (theDialog = app.dialogs.add({name:'Choose styles and options'})){ //Add a dialog column. DialogColumn1 = dialogColumns.add(); with (DialogColumn1){ staticTexts.add({staticLabel:'Endnote reference:'}); staticTexts.add({staticLabel:'Endnote text:'}); staticTexts.add({staticLabel:'Handle numbers in notes:'}); staticTexts.add({staticLabel:'Endnote separator:'}); } DialogColumn2 = dialogColumns.add(); with (DialogColumn2){ with (endnotereferencebox = dropdowns.add()){ stringList = app.activeDocument.characterStyles.everyItem().name; for (i = 0; i < stringList.length; i++){ if (stringList[i] == endnotereferencestyle){ selectedIndex = i; break; } } } with (endnotetextbox = dropdowns.add()){ stringList = app.activeDocument.paragraphStyles.everyItem().name; for (i = 0; i < stringList.length; i++){ if (stringList[i] == endnotetextstyle){ selectedIndex = i; break; } } } with (doends = checkboxControls.add()){ checkedState = true; } with (endnotesepbox = textEditboxes.add()){ editContents = endnoteseparator; } } if (theDialog.show()) { endnotereferencestyle = endnotereferencebox.stringList[endnotereferencebox.selectedIndex]; endnotetextstyle = endnotetextbox.stringList[endnotetextbox.selectedIndex]; doendnotes = doends.checkedState; endnoteseparator = endnotesepbox.editContents; switch (endnoteseparator){ case '^t': case '\t': {endnoteseparator = '\u0009'; break} case '^>': {endnoteseparator = '\u2002'; break;} case '^m': {endnoteseparator = '\u2003'; break;} case '^s': {endnoteseparator = '\u00A0'; break;} } theDialog.destroy; return(true); } else{ theDialog.destroy(); return(false); } } }