Eventually I want to build something larger but for now I am just looking for the codes to:
open document called /Users/morgan/Desktop/test.indt
save document at /Users/morgan/Desktop/test01.indd
I can’t find any examples of something so simple online. Maybe because it’s not very useful as a script. But for me to start learning it would help a lot.
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
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
It would be a good idea to add some error checking in there, especially on the save file step. It currently overwrites without asking, and you probably don’t want that longer term. You could add a step to check for an existing file, and if it exists either ask the user if they want to overwrite. Or it could automatically create a backup copy of the existing file.