Skip to main content
orib7317974
Known Participant
March 29, 2023
Question

Can I control InDesign from an outside script? Can an InDesign script interact with the OS?

  • March 29, 2023
  • 7 replies
  • 1474 views

Hello,

 

Weirdly, I was unable to find clear answers to these questions.

 

I use InDesign 2023 on a Mac. I'd like to batch process some files and extract some information from them. So I have two questions:

 

1. Can I control InDesign from an outside script? That is, is there a way to write a Python script or something that would open InDesign, tell it to open a certain file and do something with it?

 

2. Can an InDesign script (now I'm referring to a script that runs from within InDesign) interact with the OS? For instance, can such a script write to an external file?

 

Thanks!

This topic has been closed for replies.

7 replies

Brainiac
April 17, 2023

AppleScript is Apple's main script language, they also have a JavaScript engine. Common to both of is the use of AppleEvents. When I search for Python and AppleEvent, I find some references dating back to 2008, so eventually it is still built in.

https://wiki.python.org/moin/MacPython/AppleEvents

Instead of translating the entire Terminology (aka scripting object model in ExtendScript), I'd try to get the doScript method going. If that fails (e.g. removed from Python), have a look at the man page for osascript.

orib7317974
Known Participant
April 21, 2023

I'll look into this, thank you very much!

orib7317974
Known Participant
April 17, 2023

A follow-up question, please: is there a way to control InDesign with a single script that can run on both Mac and Windows?

rob day
Community Expert
April 17, 2023

JavaScript is cross platform, but it can’t control other applications that don’t have an ExtendScript API (e.g., the Finder). Using a BridgeTalk Object you can communicate with other Adobe apps, for example from InDesign you can open a linked image in Photoshop, make an edit, and save the linked image.

orib7317974
Known Participant
April 17, 2023

I understand, thank you!

orib7317974
Known Participant
March 30, 2023

@Loic.Aigon , @Kasyan Servetsky , @rob day , thank you very much for your replies, they're very helpful!

rob day
Community Expert
March 29, 2023

Here’s a simple example that opens a selected Indesign file in the Finder:

 

tell application "Finder"
	activate
	set the selected_items to the selection
	repeat with aFile in selected_items
		set thePath to (aFile as Unicode text)
		tell application id "com.adobe.indesign"
			try
				set doc to open alias thePath
				--do samething to the open document
				--close doc saving yes
			end try
		end tell
	end repeat
end tell
Kasyan Servetsky
Brainiac
March 29, 2023

I wrote a script for this task: Batch processor.

Here are examples of scripts that can be run from it.

Note a couple of scripts in the AppleScript section. They can give you an idea of how to extract info from InDesign files and put it into another app: e.g. an Excel spreadsheet.

 

Can I control InDesign from an outside script?

Many years ago I wrote a stand-alone app in AppleScript in Xcode. It was before ScriptUI became available in JS so the only option for me was to draw the dialog box in Xcode. I guess (but can’t check at the moment) that you can compile such an app in the Script Editor or Script Debugger if you want, for some reason, to control InDesign from outside instead of running a script from the Scripts panel,

 

Loic.Aigon
Brainiac
March 29, 2023

As @rob day mentioned, Applescript is your way to go. There were some great manuals in the past but most of them if not all remain valid:

chrome-extension://efaidnbmnnnibpcajpcglclefindmkaj/https://applescriptlibrary.files.wordpress.com/2013/11/indesign_scriptingguide_as.pdf

 

Once that said, to answer item #2, if you want to write an external file such as a log, you can do it with Javascript and the File Object. You can even mix Applescript for your main logic and request some javascript code in the middle (see do script).

rob day
Community Expert
March 29, 2023

Hi @orib7317974 , with AppleScript you can script both InDesign and the Finder within the same script. With Javascipt you could write InDesign and text files, but you can’t fully script the Finder.

orib7317974
Known Participant
March 29, 2023

Hey @rob day, thanks for this answer! Are there any refernces I could turn to in order to learn how to use AppleScript for my purposes? Something that tells InDesign to open a certain file and do something with it would be ideal.