Reply To: Simple script to open and save file

#98827
Mike Dean
Member

Hi Morgan,

It’s pretty simple but you have to create a new file object for both the template you’re opening and file you’re saving before you can open/save. Example code is below. Hope this helps, and good luck!


//create a new file object for the template
var templateFile = new File("~/Desktop/test.indt"); //where ~/Desktop is a username-independent path to the desktop
//open template
var template = app.open(templateFile);

//create a new file object for the test01 file
var docFile = new File("~/Desktop/test01.indd");
//save as. NOTE: This will overwrite without asking, so be careful
var doc = template.save(docFile)

//do stuff in file here

//close and save doc file
doc.close(SaveOptions.YES)

This article was last modified on October 12, 2017

Comments (0)

Loading comments...