lohriialo/indesign-scripting-python

Python scripts for InDesign on Mac

GeirOle opened this issue · 1 comments

Hello,
I would like to make scripts for InDesign in Python3 on Mac. My OS is MacOS 12.4 (Monterey).
I have made a lot of code in the past with Python 2.7, but now the most recent versions of MacOS come with Python3.
That is fine with me. I can switch to Python3.

I did the pip3 install appscript and that went well.
I found some code examples here, but they are all for Windows, and they don't work on Mac.

I have managed to start InDesign and open an InDesign document from Python3 with the following code:

###############################################################
from appscript import *
import os
app = app('/Applications/Adobe InDesign 2022/Adobe InDesign 2022.app')

myFile = '/Users/soc/test-python/test-tables.indd'
myDocument = app.open(myFile)
################################################################

In the examples I have found here the call to open a document is:
myDocument = app.Open(myFile)

That is with capital "O" in open. On Mac, that gives an error message.
So I tried with lower case "o", and then it works.

I have tried to save the document, but then I get an error message.
I have tried with

########################
myDocument.Save(myFile)
########################
and then the error message says:
Unknown property, element or command: 'Save'

If I try with lower case "s":

######################
myDocument.save(myFile)
######################

I get another error:
Command failed: Application could not handle this command. (-1708)

It is a bit strange that code which works on Windows does not work on Mac.

Has anyone managed to write Python scripts for InDesign on Mac?
Is there a reference guide somewhere?

I hope there is some information out there that can help me get going.

With best regards from

Geir