Highlighted

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

Community Beginner ,
Apr 13, 2020

Copy link to clipboard

Copied

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?

Adobe Community Professional
Correct answer by brianp311 | Adobe Community Professional

You need to create it as a file: 

 

 

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

 

Topics

Scripting

Views

117

Likes

Translate

Translate

Report

Report
Community Guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more

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

Community Beginner ,
Apr 13, 2020

Copy link to clipboard

Copied

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?

Adobe Community Professional
Correct answer by brianp311 | Adobe Community Professional

You need to create it as a file: 

 

 

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

 

Topics

Scripting

Views

118

Likes

Translate

Translate

Report

Report
Community Guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
Adobe Community Professional ,
Apr 13, 2020

Copy link to clipboard

Copied

You need to create it as a file: 

 

 

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

 

Likes

Translate

Translate

Report

Report
Community Guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
Reply
Loading...
Community Beginner ,
Apr 14, 2020

Copy link to clipboard

Copied

Worked perfectly! Thank you. 

Likes

Translate

Translate

Report

Report
Community Guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
Reply
Loading...