Skip to main content
Inspiring
April 13, 2020
Answered

"Cannot open [FILE].indd" when trying to Save A Copy via script.

  • April 13, 2020
  • 2 replies
  • 492 views

Hello. I am fairly new to Indesign scripting. I am writing a simple javascript for archiving versions of my InDesign work by date and time. The script works and does the following. 

  • Creates a folder called "Archive" in the same directory of my active Indesign document. 
  • Exports a pdf of my active document into this Archive directory
  • Appends the current timestamp to the file name of the exported pdf. 
  • Saves a copy of the InDesign document into the archive directory
  • Appends the current timestamp to file name of the InDesign document

 

The script is below:

// Define App, Document, Filepath, Current Document Name
myApp = Application;
doc = app.activeDocument;
docPath =doc.filePath;
docName = doc.name

// Get current Timestamp & strip unwanted characters
myDate = new Date().toString();
cleanDate = myDate.replace(/:/g, "");
cleanDate = cleanDate.replace(" GMT-0400", "");

// Create new names for PDF and INDD document with timestamp appended to end
newDocName = docName.replace(".indd",  "-[Saved " + cleanDate + "].indd");
exportDocName = docName.replace(".indd",  "-[Saved " + cleanDate + "].pdf");

// create a folder to hold archived copies in same directory as the source file. Store the path to new folder.
archiveFolder = new Folder(docPath + "/Archive/");
archiveFolder.create();
aPath = archiveFolder.getRelativeURI();

// Export the PDF in the archive folder, Prompt user for settings.
doc.exportFile(ExportFormat.pdfType, File(aPath + "/" + exportDocName), true);

// Save a copy of the Indesign file in the archive folder. 
doc.saveACopy((aPath + "/" + newDocName), false);

 

This script is crude and needs some error checking, but it does all of the desired behaviors above. The problem I am having is that I get an error when running the last line saying that it "Cannot open "Foo-[Saved Mon Apr 13 2020 160852].indd". Running the script inside Indesign produces Error 3588 and Error code 6 "File was not found". I am not trying to open any file with the script, and my understanding is that saveACopy() does not open any files. Can anyone help me figure out why I am getting this error?

This topic has been closed for replies.
Correct answer brian_p_dts

You need to create it as a file: 

 

 

doc.saveACopy(File(aPath + "/" + newDocName), false);

 

2 replies

Inspiring
April 14, 2020

Worked perfectly! Thank you. 

brian_p_dts
Community Expert
brian_p_dtsCommunity ExpertCorrect answer
Community Expert
April 13, 2020

You need to create it as a file: 

 

 

doc.saveACopy(File(aPath + "/" + newDocName), false);