• Global community
    • Language:
      • Deutsch
      • English
      • Español
      • Français
      • Português
  • 日本語コミュニティ
    Dedicated community for Japanese speakers
  • 한국 커뮤니티
    Dedicated community for Korean speakers
Exit
0

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

Participant ,
Mar 29, 2023 Mar 29, 2023

Copy link to clipboard

Copied

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!

TOPICS
Scripting

Views

748

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Expert ,
Mar 29, 2023 Mar 29, 2023

Copy link to clipboard

Copied

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.

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Participant ,
Mar 29, 2023 Mar 29, 2023

Copy link to clipboard

Copied

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.

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
People's Champ ,
Mar 29, 2023 Mar 29, 2023

Copy link to clipboard

Copied

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).

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Guru ,
Mar 29, 2023 Mar 29, 2023

Copy link to clipboard

Copied

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,

 

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Expert ,
Mar 29, 2023 Mar 29, 2023

Copy link to clipboard

Copied

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

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Participant ,
Mar 30, 2023 Mar 30, 2023

Copy link to clipboard

Copied

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

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Participant ,
Apr 17, 2023 Apr 17, 2023

Copy link to clipboard

Copied

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

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Expert ,
Apr 17, 2023 Apr 17, 2023

Copy link to clipboard

Copied

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.

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Participant ,
Apr 17, 2023 Apr 17, 2023

Copy link to clipboard

Copied

I understand, thank you!

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Guide ,
Apr 17, 2023 Apr 17, 2023

Copy link to clipboard

Copied

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.

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Participant ,
Apr 21, 2023 Apr 21, 2023

Copy link to clipboard

Copied

LATEST

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

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines