Skip to main content
Participant
October 16, 2007
Question

COM under Macintosh

  • October 16, 2007
  • 9 replies
  • 898 views
Under Windows you can communicate with InDesign using COM (all on one machine).

Since OS X, Mac supports COM. Is it possible on to communicate with InDesign via COM on a Macintosh (all on one machine). Is InDesign also a Com server on the mac? Is this how the extended script functionality is working?

Has anyone seen any source code (or application) that does this?

any insights would be great.

thanks.
This topic has been closed for replies.

9 replies

Inspiring
October 19, 2007
Back in '99 I wrote a similar utility that generates the whole required code from the AppleEvent. It hasn't seen much work recently and does not yet support the Get AETE event, so you can't just turn it towards InDesign without extra work.

Due to size, I've sent you a sample output off list.
That generated code sends some junk towards Netscape 4, but it should be easy to adjust it for your InDesign event. At least I hope so, the file had a timestamp of 2003.

Dirk
Participant
October 19, 2007
Thanks again for helping me along my way to immersing myself in Apple interprocess communication.

For reasons of performance I decided to go the AppleEvent way instead of the AppleScript way.

I decided to put here my experiences, in case anyone else is trying to solve a similiar problem.

Here is brand new stuff which looks promising:
Leopard's new Scripting Bridge is something I want to try soon.
And the Java-AppleScript-Connector - https://jasconn.dev.java.net/ (only works under java 6).

I couldn't get : AppleEvent_Send_and_Receive to work. Not sure why.

However I did change this example and managed to send a message to Finder:
http://developer.apple.com/samplecode/QCCocoaComponent/index.html

But then when I tried to send my own arbitrary AppleEvent to InDesign that didn't work.

By using this bash script (to put InDesign in AppleEvent logging mode):
set -a
AEDebug=1
AEDebugSend=1
AEDebugReceives=1
open "Adobe InDesign CS3.app" &

and looking in the console and executing this AppleScript:

tell application "Adobe InDesign CS3"
set myDocument to make document
tell page 1 of myDocument
set myTextFrame to make text frame
set geometric bounds of myTextFrame to {"6p", "6p", "24p", "24p"}
set contents of myTextFrame to "Hello World!"
end tell
end tell

I managed to get a very nice AppleEvent (this is the first one)

------oo start of event oo------
{ 1 } 'aevt': core/crel (ppc ){
return id: 142016686 (0x87700ae)
transaction id: 0 (0x0)
interaction level: 64 (0x40)
reply required: 1 (0x1)
remote: 0 (0x0)
target:
{ 1 } 'psn ': 8 bytes {
{ 0x0, 0x200001 } (Skripteditor)
}
optional attributes:
{ 1 } 'reco': - 2 items {
key 'subj' -
{ -1 } 'null': null descriptor
key 'csig' -
{ 1 } 'magn': 4 bytes {
65536l (0x10000)
}
}

event data:
{ 1 } 'aevt': - 1 items {
key 'kocl' -
{ 1 } 'type': 4 bytes {
'docu'
}
}
}

But I couldn't figure out how to send the thing in my Objective-C code. hmm.

Regards

kent
Inspiring
October 16, 2007
A minimum jni library only needs one method - doScript. It could do that through calls to AECreateAppleEvent, AESend and so forth, read on here:

http://developer.apple.com/documentation/mac/IAC/IAC-195.html

You then use that doScript to send javascript code, pass parameters and retrieve the result. All details can be handled with plain java, if you have done the TLB parsing for Windows you just build on that data to generate wrappers rather than work your way through AETE resources (or whatever Apple now uses instead).

http://developer.apple.com/documentation/mac/IAC/IAC-299.html

Of course whether this way is feasible also depends on your speed requirements, sending everything through Java wrappers, JS codegen / mangling, AppleEvent packaging, inter process communication, AE decoding, dispatching and not to forget the JS interpreter will take its toll. But with Java around we're not shy to waste a few CPU cycles anyway.

Anything more sophisticated would IMO go beyond the scope of this forum, at least at 1 AM this side of the atlantic.

Dirk
Participant
October 16, 2007
Dirk,

could you fill me in a bit more about your jni solution (my COM solution used jni to model the whole object model)? My problem is that I don't know the apple world. Ok so it seems pretty clear, I will not be talking jni to a COM object on a mac. What libraries or objects on the mac side can I need to talk with in order to get InDesign to do my bidding? And where do I get the IDL / Type Libary (is this the dictionary)? (by the way the java code does not need to be interactive).

Sorry to keep digging, but you seem to know your stuff. One last thing, you mention "license reasons". I have tried to educate myself about this to avoid any mistakes, and I can't seem to find many restrictions. The eula delivered with InDesign and with the InDesign sdk, restricts certain normal things like decompiling etc, but what I have not seen is anything that say prohibits building a java api that is similar to what the server has, could I be wrong, have I missed an important document?

Further to Eugenio's post it almost seems as if the dictionary is a type library (thanks for the links). Which could mean that I could maybe do something like this:

windows setup:
pure java api calls jni which calls com

mac:
pure java api calls AppleScript which calls InDesign

kent
Inspiring
October 16, 2007
Ages ago (around 1999) there was MRJ which supported AESend etc.
If you Google these keywords you end up with "Legacy" warnings but no replacement.
http://developer.apple.com/samplecode/AppleEvent_Send_and_Receive/index.html

Approaches:
- provide your own JNI glue. Last time I did that is 10 years ago so don't give too much on my estimates, but the task should be achievable within a few days if you just send JavaScripts instead of mapping the whole object model.
- Have a look into InDesign server which is accessible via SOAP and is said to have Java bindings (I never tried and fear it is just SOAP wrappers). This won't help if your Java code is intended to assist a human operator. Otherwise you might anyway need InDesign Server for license reasons.
- open a socket to a telnet port on localhost, and fire off AppleScript code using OSAScript. Be prepared that AppleScript follows Apple's "Think different".

Dirk
Participating Frequently
October 16, 2007
Hi Kent,

The dictionary is a part of the executable and can be extracted by special programs. I would recommend that you get "Script Debugger 4", which is a shareware product that is quite indispensable if you want to program with AppleScript. Mac OS has some tools, but they are much inferior to that.

Script Debugger will let you see any dictionary and what it can do. You can program in JavaScript or AppleScript. As Dirk pointed out, the communication is via AppleEvents. This is independent from the "internal" scripting of InDesign. From an external script (or an application that can call or execute a script) you can control InDesign quite a bit. There are also ways to call external scripts from applications, e.g. calling the "osascript" Mac/Unix executable.

I would advise you to read "AppleScript: The Definitive Guide, 2nd Edition". You also have some introductory materials about AppleScript on the Apple site. Also the InDesign scripting documentation talks about AppleScript. Get it from Adobe if you don't have it.

But if you don't want to control InDesign as such, but only want to communicate with your plugin, you are probably better off using one of the inter-process communication mechanisms that the Mac supports, like pipes or sockets.

Hope that helps,
Eugenio Andres - http://www.ExpertosInformaticos.com
Participant
October 16, 2007
Thanks for the pointers.

Let me explain what I am doing a bit.

I have a java client which can successfully communicate via COM to the InDesign client, all of this on a pc.

What I would like is to do the same thing on a Mac, but I am bit lost in the mac world ( I want to support mac and pc with the same code as much as possible).

I would like to do it with COM, but I suspect this not possible because there is a good chance that on the Mac InDesign is not a COM server. Dirk says, the ExtendScript bypasses the ApplEvents layer, but I still wonder how the interprocess communication is handled.

Also, I thought maybe a lot changed in regards to scripting between cs2 and cs3, is COM somewhere in there now?

How does this "dictionary" mechanism work? In windows this is called a typed library. InDesign has an extensive typed library that I can convert to java proxies. Like I said I would like to use these same java proxies to contact InDesign. Is this something worth investigating?

ps good point about the better search keyword, yup COM sure fails in this way.
Inspiring
October 16, 2007
Actually the inter process communication used by the AppleScript language and others is called AppleEvents. Makes a better search keyword ...

Anyway the question about COM is still good - I once did a small PDA project with C# and liked it better than Java. Since then I keep half an eye on Mono and would like to see it connected to InDesign somehow - probably that would mean COM. On the other hand the desire is not strong enough to throw in own work here.

To the original question, ExtendScript bypasses the whole AppleEvents layer and connects straight to the script handler / provider etc classes. Scripts are executed within the InDesign process, only talking to other Adobe applications requires BridgeTalk.

Dirk
Participating Frequently
October 16, 2007
Hi Kent,

On the Mac you usually use AppleScript for this. The Apple scripting mechanism sends messages between applications to open files, close applications, etc. Every scriptable application (like InDesign) includes a "Dictionary" of objects, actions, etc. you can use with it. InDesign's Dictionary is pretty extensive.

Hope that helps.
Eugenio Andres - Expertos Informaticos - http://www.expertosinformaticos.com