How to create a Batch Script for InDesign files?
Copy link to clipboard
Copied
Apologies if this is a question that has been answered (or is regularly asked)
Wanting to record a set of instructions in an Indesign file like you can do in Photoshop where you could run that as a batch against a folder full of files.
Eg of Instructions would be:
1. Open File
2. Find text eg. 27 July 2023
3. Change text to. eg 12 October 2023
4. Save file
5. Export file as a PDF to a different folder
Copy link to clipboard
Copied
Hi Tim,
InDesign does not have any feature to record an operation. You could use the following code, make the appropriate changes like the path of the INDD and PDF file and also the string to search and the string to use as the replacement.
var doc = app.open("/Users/manan/Downloads/sample.indd")
app.findTextPreferences = app.changeTextPreferences = null
app.findTextPreferences.findWhat = "27 July 2023"
app.changeTextPreferences.changeTo = "12 October 2023"
doc.changeText()
app.findTextPreferences = app.changeTextPreferences = null
doc.exportFile(ExportFormat.PDF_TYPE, "/Users/manan/Downloads/sample.pdf", false)
doc.close(SaveOptions.YES)
-Manan
Copy link to clipboard
Copied
Thank you Manan, and where do I run the script from? Is it somewhere within InDesign or in an external program? New to this type of thing.
Copy link to clipboard
Copied
Check out the following article to know about how to run the script
https://creativepro.com/how-to-install-a-script-in-indesign-that-you-found-in-a-forum-or-blog-post/
Also, JS would run both on the MAC as well as WIN so you are good to go
-Manan
Copy link to clipboard
Copied
@Manan Joshi Appreciate your help.
Is it possible to do a script that will open up multiple InDesign files within a folder and do this?
With the script above you would have to run it individually for each file right?
Copy link to clipboard
Copied
Try the following code, it will ask for the folder to scan for InDesign files and will then do the change in any indd file it finds in the folder and exports the pdf with the same name in a folder whose path can be set in the first line of the code
var exportFolder = "/Users/manan/Downloads"
var myFolder = Folder.selectDialog("Select a folder with InDesign files");
if (!myFolder)
exit(0);
var myFileList = myFolder.getFiles();
for (var i = 0; i < myFileList.length; i++) {
var myFile = myFileList[i];
var fName = myFile.name.match(/(.*)\.indd$/i)[1]
if (myFile instanceof File && myFile.name.match(/\.indd$/i)) {
var doc = app.open(myFile);
app.findTextPreferences = app.changeTextPreferences = null
app.findTextPreferences.findWhat = "27 July 2023"
app.changeTextPreferences.changeTo = "12 October 2023"
doc.changeText()
app.findTextPreferences = app.changeTextPreferences = null
doc.exportFile(ExportFormat.PDF_TYPE, exportFolder + "/" + fName +".pdf", false)
doc.close(SaveOptions.YES)
}
}
P.S. :- The code to loop over InDesign files in a folder is picked from the following post
-Manan
Copy link to clipboard
Copied
If you work on a PC - my ID-Tasker is EXACTLY for this.
Even the free version can do this - and WAY more.
Copy link to clipboard
Copied
Thanks Robert, the person I'm trying to help with this works on a PC so much appreciated.
What would someone on a MAC have to use? Just curious.
Copy link to clipboard
Copied
There are some tools for batch processing - but they are rather limited to a single / specific operation...
With ID-Tasker - you can do whatever you want - and process in the same way - or conditionally - whole servers of files...

