Skip to main content
Known Participant
November 1, 2008
Question

looking for a script to import/export all footnotes on a MAC/CS3

  • November 1, 2008
  • 29 replies
  • 3180 views
To all you amazing scripting gurus,

CS3 on a MAC. I am faced with an awkward situation. I am given a 300+ scientific document with 400+ footnotes that they keep on changing ALL THE TIME.

i Is there a script that would import into inDesign the footnotes from another doc/txt/csv file and replace the ones to their already existing reference avoiding overflows and at the same time applying a defined paragraph style? As an extra bonus it would be even greater if one could have an option do the reverse. That is to select all the existing footnotes in an indesign document and export them to a doc/txt/csv file. This way editors can play to their heart's desire and it would be a real treat for designers.

I know it is quite a challenge since inDesign does not even have an option to select all footnotes. But I've seen what you experts can do with scripts.

Keeping my hopes high, thank you all in advance
Michael
This topic has been closed for replies.

29 replies

November 6, 2008
I feel for you and your problem... I see typesetters all over the planet reaching out to choke the editors on your project. Good on you, Kasyan, for helping as you are.
Known Participant
November 5, 2008
Kasyan,

I still get the same error. Could it be due to my file itself? If it is any help, you can find the file here.
http://www.aenaon.info/toget/footnotesTEST.indd.zip

Also thank you for the tips on removing the file extensions. They come really handy.

Michael
Kasyan Servetsky
Legend
November 5, 2008
>But it imports the extension as well. How can I get rid of that?

I know a few more ways:

//creates an array from a string
//returns the first item in the array
myLink.name.split(".")[0];

var basename = docName.match(/(.*)\.[^\.]+$/)[1];

//Strip off the file type extension (dot and 3 characters)
myFileName.slice(0,-4);

function getFileNameOnly (myFileName) {
var myString = "";
var myResult = myFileName.lastIndexOf(".");
if (myResult == -1) {
myString = myFileName;
}
else {
myString = myFileName.substr(0, myResult);
}
return myString;
}
Kasyan Servetsky
Legend
November 5, 2008
I tested it on a very simple document: one page and 3 footnotes. Its hard for me to foresee what is going on with the document that you are working on.
Lets make a step backward and remove the problem line to make things simpler:

// footnotes2text script for InDesign CS3

footnotes2text();

function footnotes2text(){
var myFolder = new Folder ("~/Desktop/Footnotes");
if (!myFolder.exists) {
myConfirm = confirm("Folder \"Footnotes\" does not exist. Do you want to create it?");
if (myConfirm){
myFolder.create();
}
else{
exit();
}
}
var myDoc = app.activeDocument;
for( var i = 0; i < myDoc.stories.length; i++ ) {
var myStory = myDoc.stories;
var myFnotes = myStory.footnotes;
for( var j = 0; j < myFnotes.length; j++ ) {
var myFilePath = myFolder + "/" + myStory.id + "_" + myFnotes.id + ".txt";
var myFile = new File(myFilePath);
myFile.open("w");
myFile.write(myFnotes.contents);
myFile.close();
}
}
}

// text2footnotes script for InDesign CS3

text2footnotes();

function text2footnotes() {
var myFolder = new Folder ("~/Desktop/Footnotes");
if (!myFolder.exists) {
myConfirm = confirm("Folder \"Footnotes\" does not exist. Do you want to create it?");
if (myConfirm){
myFolder.create();
}
else{
exit();
}
}
var myDoc = app.activeDocument;
for( var i = 0; i < myDoc.stories.length; i++ ) {
var myStory = myDoc.stories;
var myFnotes = myStory.footnotes;
for( var j = 0; j < myFnotes.length; j++ ) {
var myFilePath = myFolder + "/" + myStory.id + "_" + myFnotes.id + ".txt";
var myFile = new File(myFilePath);
if (myFile.exists) {
myFile.open("r");
myFnotes.contents = myFile.read();
myFile.close();
}
}
}
}
Known Participant
November 4, 2008
I solved the mystery of the jpg's filename into the images caption. I replaced the above code with this one.

var md = sels.synchronousMetadata;
md.namespace = "http://ns.adobe.com/photoshop/1.0/";
md.Caption = sels.name.replace (/\.[^.]+$/, "");
Known Participant
November 4, 2008
Hi Kasyan,

I tried the scripts but they both seem to get stuck giving an error at:

Error Number: 45
Error String: Object is invalid
Line: 20
Source: var my1st3words = myFnotes.words.itemByRange(0, 2).contents;

Any suggestions?

Thank you
Michael

By the way. I work on another script script and managed to import a jpg's filename into the images caption. But it imports the extension as well. How can I get rid of that?

var md = sels.synchronousMetadata;
md.namespace = "http://ns.adobe.com/photoshop/1.0/";
md.Caption = sels.name;
Kasyan Servetsky
Legend
November 4, 2008
>Is there a script that could do the above?

In all likelihood there is no such a script. I’ve been monitoring this forum for a few years and keep an eye on different sites but never came across it.

But here is what I knocked up: 2 scripts – one of them exports contents of footnotes into separate text files into a “Footnotes” folder on the desktop.
The names of files are as made like so:
First three words_ StoryId_ FootnoteId.txt
Where – “First three words” is for humans, and “StoryId_ FootnoteId” for the script — to differentiate footnotes.
It’s a very raw, preliminary and totally not tested version – just to give you idea how this can be done. The final version depends of your workflow.
You can download them from here: http://www.kasyan.ho.com.ua/footnotes.html

Kasyan



// footnotes2text script for InDesign CS3
footnotes2text();

function footnotes2text(){
var myFolder = new Folder ("~/Desktop/Footnotes");
if (!myFolder.exists) {
myConfirm = confirm("Folder \"Footnotes\" does not exist. Do you want to create it?");
if (myConfirm){
myFolder.create();
}
else{
exit();
}
}
var myDoc = app.activeDocument;
for( var i = 0; i < myDoc.stories.length; i++ ) {
var myStory = myDoc.stories;
var myFnotes = myStory.footnotes;
for( var j = 0; j < myFnotes.length; j++ ) {
var my1st3words = myFnotes.words.itemByRange(0, 2).contents;
var myFilePath = myFolder + "/" + my1st3words + "_" + myStory.id + "_" + myFnotes.id + ".txt";
var myFile = new File(myFilePath);
myFile.open("w");
myFile.write(myFnotes.contents);
myFile.close();
}
}
}



// text2footnotes script for InDesign CS3
text2footnotes();

function text2footnotes() {
var myFolder = new Folder ("~/Desktop/Footnotes");
if (!myFolder.exists) {
myConfirm = confirm("Folder \"Footnotes\" does not exist. Do you want to create it?");
if (myConfirm){
myFolder.create();
}
else{
exit();
}
}
var myDoc = app.activeDocument;
for( var i = 0; i < myDoc.stories.length; i++ ) {
var myStory = myDoc.stories;
var myFnotes = myStory.footnotes;
for( var j = 0; j < myFnotes.length; j++ ) {
var my1st3words = myFnotes.words.itemByRange(0, 2).contents;
var myFilePath = myFolder + "/" + my1st3words + "_" + myStory.id + "_" + myFnotes.id + ".txt";
var myFile = new File(myFilePath);
if (myFile.exists) {
myFile.open("r");
myFnotes.contents = myFile.read();
myFile.close();
}
}
}
}
Known Participant
November 4, 2008
Hi Kasyan and thanx for the quick reply,

Still, I think you are talking about a completely different ball game.
You see I know that for the time being this would be both a money issue (since neither myself -I only have Bridge/Photoshop/InDesign CS3- or the editor who happens to be the college secretary, have InCopy) as well as a time issue (since, as I saw at the Adobe site, it would take quite some training hours for the two of us in order to have decent results). Quite unfortunate but true.
Still your answer is highly appreciated.

So the question still remains for you or anyone else that could probably provide any kind of help.
b Is there a script that could do the above?

Thank you in advance
Michael
Kasyan Servetsky
Legend
November 3, 2008
Hi Michael,

You don’t need a script for this, as InDesign combined with InCopy (http://www.adobe.com/products/incopy/ ) already has this functionality.
Briefly, InCopy is a text editor made to work together with InDesign and having the same functionality for working with text as InDesign has. It will enable you and your editors to work on the same InDesign document simultaneously. You just have to decide which stories you want the editors to edit — all stories in the document / on the active layer / selection — and choose Edit > InCopy > Export. After that these stories become available to editors for editing in InCopy. You can edit the text in InDesign as well, but two people can’t edit the same text at the same time of course — if somebody has already opened a text, it becomes locked for others. You can even work with your editors remotely: via e-mail.
InDesign and InCopy are totally cross platform, so if you work on Mac and the editors on PC, no problems will occur as far as you use the same set of fonts.
We’ve been using this workflow for a few years and now can’t even imagine our life without InCopy.

Kasyan