Using AI to Write Scripts
How to use ChatGPT or Copilot to write custom scripts for your Adobe apps

This article appears in Issue 35 of CreativePro Magazine.
You’ve probably noticed that, since mid-2022, an army of new AI apps, features, and tools have invaded the design world, promising to “unlock your creativity” and, maybe, put you out of a job. Designers and nondesigners are now playing art directors to a team of literal-minded and often inept generative AI “artists.”
Ownership (or what some call theft) of content is a fraught issue that will eventually work its way through court cases, establish legal precedent, and perhaps prompt legislation. Even as Adobe has tried to take a moral high ground, the company is hurting its Adobe Stock contributors by allowing AI content into its software and stock image ecosystem.
ChatGPT and its kin have already created—if you can call it that—entire libraries of cringeworthy content. And there’s the whole “Is it art?” question. That one’s been popping up regularly since the dawn of photography, almost two centuries ago.
But between the extremes of giddy excitement and existential dread surrounding this new generation of AI tools, there is a middle ground. AI is also a tool that can help you get real work done.
A Case Study
Production work can be repetitive, especially with rounds of submissions, internal client meetings, and oh-by-the-way amendments. You can find yourself repeatedly doing minor-but-essential actions that are as creative as a drainpipe and half as much fun.
That happened to me on a recent project. I had completed the identity design work for a large set of short training manuals. Now I had to compile and typeset them from the manuscript library, in subsets of a dozen or more at a time.
To speed up the process, I equipped my InDesign templates with all the necessary paragraph, character, table, and object styles.
I set up the import presets (using Em Software’s fantastic WordsFlow plug-in) for the copy, saved find/change queries for quick execution, and set up a couple of other production aids.
But one thing irked me: Often, sometimes several times a day, I had to export complete sets of documents as individual PDFs for client proofreading and review. Mindlessly pressing the same key sequence over and over does not make my day bright and cheerful.
A script would be a perfect solution. But I’m not a scripter.
But like most of us, I had been playing around with ChatGPT, although never for anything you’d call serious work. Perhaps, I thought, it knows InDesign. Maybe it could write me a custom script!
I decided to give it a try and fired up Copilot (Microsoft’s implementation of ChatGPT) from my Windows desktop.
I wanted the script to automate what I was doing by hand, so I thought through the steps:
- Pick a PDF preset (High Quality Print for proofing, PDF/X-1a with bleed for printing).
- Export the current document.
- Tab to the next document.
- Rinse and repeat until done.
- That gave me a starting point.
The Conversation
Here is my conversation with Copilot, edited lightly for clarity and to avoid redundancy.
Me: Write me JavaScript code to cycle through a set of open documents in Adobe InDesign and export each one to PDF.
The script failed with an error. After some poking around and reading the generated code more carefully, I realized the GPT had a name wrong.
Me: The error was that the preset name is not “High Quality Print”. It is “[High Quality Print]”. Without the square brackets the name is invalid.
Copilot: Ah, I see. The square brackets are indeed part of the preset name in Adobe InDesign. Here’s the corrected JavaScript code with the proper preset name:
This version of the script worked as expected.
Me: Build on that core script to create a version that takes a list of PDF presets from a text file and asks the user to choose one before using it to execute the export sequence.
Copilot: Certainly! Below is an enhanced JavaScript script for Adobe InDesign that reads a list of PDF export presets from a text file, prompts the user to choose one, and then exports all open documents using the selected preset.
This version of the script worked as expected.
Me: Modify the script to create a dropdown list of the PDF presets for the user to select from. The new script should look for the PDF presets text file in the same directory as the script itself.
Copilot: Here’s the updated JavaScript for Adobe InDesign that creates a dropdown list for the user to select a PDF preset. The script will look for the pdf_presets.txt file in the same directory as the script itself.
This version of the script worked as expected.
Me: Add a check to ensure that at least one document is open before executing the script. If no documents are open, the script should terminate with an error message telling the user why. Also add a check to see that the presets file exists. If it does not, terminate with a message saying, “The PDF presets file must exist in the same folder as this script.”
Copilot: Here’s the updated script with the requested checks for open documents and the existence of the presets file.
This version of the script worked as expected.
Me: Add a message when the script completes, to notify the user that all PDFs have been successfully exported.
Copilot: This script will now display a message at the end of the execution to inform you that all documents have been successfully exported to PDF. If you need any more help or further customization, feel free to ask!
And that version of the script also worked perfectly.
Notice that, in the dialog with Copilot, I started with the simple core operation (exporting each document as a PDF) before adding the bells and whistles one at a time. That allowed me to keep track of what Copilot was building and to catch any errors.
I saved the script as All_ExportToPDF.js exactly as Copilot wrote it, with a little introduction from me at the top. I might not have ended up with the most elegant or efficient bit of code, but it does exactly what I needed, quickly and efficiently—and it took only a few minutes to create.
Because I use it often, I’ve given it a keyboard shortcut, so I don’t even have to open the Scripts panel.
Note: You can download both of the scripts described in this article. You can find instructions on how to install and run scripts here.
Be Exact
Be very specific about what you ask for when prompting an AI tool for a script. Here is an example that benefitted from that specificity.
I asked Copilot to solve an annoying problem: You can’t use a keyboard shortcut to apply one paragraph style and its next style. (You have to use the Paragraph Styles panel menu or Quick Apply.)
I made my prompt in this case as specific as I could:
I need an InDesign script that takes a text selection and applies a paragraph style to the first paragraph of the selection, then applies its “Next Style” to the following paragraph, then that style’s “Next Style” to next paragraph, and so on until all paragraphs in the text selection have had a style assigned. The first paragraph style is contained in a text variable called “ParaStyle.” The script should check for the existence of this text variable and create it if it does not exist. It should verify that it contains a valid paragraph style name and create one if it does not exist. It should exit with an error message if necessary.
Copilot got this one right the first time. Remarkable!
To run this script—AndNextStyle.jsx—create the text variable ParaStyle mentioned in the prompt if it’s not there (Figure 1). Once that’s done, the script runs perfectly.

Figure 1. The script requires a text variable to be defined with the name of a paragraph style that will be applied to the first paragraph in a text frame.
I used it to format Daniel Defoe’s novel about the Great Plague of London, which contains a very long proclamation by the Lord Mayor. The text consists mostly of headings followed by single paragraphs followed by the next heading, and so on. It would be a very tedious thing to format without some sort of automation.
I set up the ParaStyle text variable with a value of Heading, as in Figure 1. The Heading paragraph style has a next style of Quoted (Figure 2), and the Quoted style, in turn, has a next style of Heading (Figure 3).

Figure 2. The Heading paragraph style defines a Next Style of Quoted.

Figure 3.The Quoted paragraph style defines a Next Style of Heading.
Figure 4 shows the text (shown selected) before and after running the script.
Every paragraph style has a default Next Style of Same Style, so you don’t have to add a Next Style if it’s not required.
Getting Fancy Requires Care
When you’re dealing with an AI, keep in mind that its so-called intelligence doesn’t equate to sensibility, rationale, or accuracy. (In fairness, recall that you’ve likely known a few clever humans who also fit that description.)
Copilot will warn you about this at the end of each script it generates: “AI-generated code. Review and use carefully.” It’s good advice. Copilot can make some amazing blunders, because it doesn’t have common sense. (You have been warned.)
You’re Never Alone With an AI
You won’t turn to Copilot, ChatGPT, or similar resources every time InDesign throws you a problem to solve, but knowing that you can quite easily generate a custom script means that you can afford to consider that as a viable tool, even if it’s only good for one or two projects.
Artificial intelligence isn’t going to solve every tedium in your production work, but with some careful planning, it might be just the thing you need.
Commenting is easier and faster when you're logged in!
Recommended for you

Remove a Complex Background with One Click in Photoshop
The foundation of great image editing is accurate selections, and the AI selecti...

How to Use Illustrator’s New Generative Expand
Take a first look at how to use Illustrator’s new Generative Expand feature and...

A Formula for Success: InDesign + MathML
Learn the ins and outs of writing precise, accurate, and accessible formulas usi...