Skip navigation
Rafael Paz2
Currently Being Moderated

Manipulate Indesign cliente from a Java Application

Jul 24, 2012 5:55 AM

Tags: #java #client #indesign

Hello, I need to manipulate Indesign client(open/close documents, create menus, tables, set colors etc... ) but I need to do that from a Java application. Is it possible? I was searching on google about it, even in Adobe's site, but the only way I found was thought Javascript, VbScript or AppleScript.

 

 

Thanks in advance!

 

Rafael

 
Replies
  • Currently Being Moderated
    Jul 27, 2012 1:55 PM   in reply to Rafael Paz2

    I can control inDesign from Python or shell scripts on osx via `osascript` This is roughly how it works.

     

    1. My 'master' program runs shell command `osascript -e "tell Indesign blahblah end tell" /path/to/temporary.jsx`  
    2. `osascript` tells Indesign to execute "/path/to/temporary.jsx" as javascript
    3. If all goes well, the value of last expression  in .jsx is returned by `osascript` (serialised JSON works great for this)

    Sorry I'm vague on real life code, but this is my home machine so it's not in my reach.

     

    I realise it's an ugly hack. Main cons follow:

    • quotes have to be escaped couple of times so the result is messy and prone to errors (luckily it's one-off code that sits hidden behind main interface)
    • debugging this chain is nightmare (especially with my nigh-zero knowledge of applescript)
    • so far it's mac only (I suspect same thing can be achieved on Windows machine with VBS)
    • one cannot avoid writing lots of temporary files to the system. (luckily for me, it's only deployed on machines under my control, so the temp files are written to /tmp which is mounted on ramdisk)

     

    The only pro I can think of is that it works. Whole comlexicity is wrapped in one python module, which I only see when squashing the bugs.

     

    Marcel

     
    |
    Mark as:
  • Currently Being Moderated
    Jul 30, 2012 2:25 AM   in reply to hugli2

    OK so here's what I use to run JSX file from shell

    osascript  -e 'tell application "Adobe InDesign CS5" to do script alias "%s" language javascript ''' 
    

    where %s is path to the script.

    There's probably a way to run an extendscript statement instead of a file, but my applescript skills are too limited for that. Besides it uses all sorts of quotation marks already.

    Imagine escaping all quotes in your javascript and than escaping the whole thing before you call it from your Java, Python whatever app.

     

    I've no idea what the visual basic equivalent for windows should look like, but I'm sure there's some VB guru around willing to help

     

     

    (Slightly related) syntax sugar:

    If you put this to your InDesign startup script:

    #targetengine "session"

    Application.prototype.shell = function (shell_script){                                                                                                               var apple_script = 'do shell script "' + shell_script + '"'     var output = app.doScript (apple_script, ScriptLanguage.APPLESCRIPT_LANGUAGE)     return output     };

     

    You will have `app.shell()` method available in any script executed in "session" targetengine. Now you can return your Java app favour and call it comfortably from Indesign

     
    |
    Mark as:
  • Currently Being Moderated
    Jul 30, 2012 6:21 AM   in reply to Rafael Paz2

    I don't know much about Java, but that code seems to be Windows only. Anyway, I wish you good luck teaching Java & InDesign talking to each other.

     

     

    Just out of curiosity, what do you mean by "searching Jacob"?

     
    |
    Mark as:
  • Currently Being Moderated
    Jul 30, 2012 8:43 AM   in reply to Rafael Paz2

    And don't forget it's for 32 Bit Systems only.

    There is also Jawin Library, but the same problem - 32 Bit.

    We had some experience with Jawin.

    I wouldn't recommend it to anyone.

     

    Now we use ID Server and SOAP Interface.

     
    |
    Mark as:
  • Currently Being Moderated
    Jul 30, 2012 3:26 PM   in reply to Rafael Paz2

    My first attempt was an ExtendScript socket polled from within InDesign, and used to bounce scripts back and forth via eval() and/or Json. I found out the hard way though, that at least on OSX the last thing that ExtendScript will do is an attempt to write to a broken socket, whenever I prematurely close the other side e.g. by debugger kill. Besides CS5 idle events apparently stop working when InDesign is in background.

     

    In a CS4 production environment I'm using a custom plugin for idle notifications, it also helps to pre-filter selection events to our purposes.

     

    My latest experimental environment is Java on OSX which provides AppleScript as scripting engine (via javax.script), no need to use the shell or temporary files. I've been using it for a few months. With some glue code here and a few more wrapper objects there, it is fun to have a true IDE with Java code completion, javadoc help and syntax checking on InDesign scripts ...

     

    Of course this setup comes at the cost of a slight speed penalty; I still have not found a good approach for methods that return variants (different types on different occasions) and objects that change their type on the fly are still a pain.

     

    Thanks for the pointers to Jacob and Jawin, are there any experiences with j-Interop?

     

    Dirk

     
    |
    Mark as:
  • Currently Being Moderated
    Jul 31, 2012 6:25 AM   in reply to Rafael Paz2

    Very simple functionality like one from Tutorial will work.

    But when you start to do some complex things it's not very reliable.

    IMHO. If it works for you, that's fine.

     
    |
    Mark as:
  • Currently Being Moderated
    Jul 31, 2012 6:53 AM   in reply to Rafael Paz2

    We have not found cool alternative

    As I remember I've found that some methods or properties were not implemented in stub generated with Jawin.

    So we changed to InDesign Server. With SOAP you can relative easy start any script on Server.

    But if Jacob is OK for your tasks, it's nice.

     
    |
    Mark as:
  • Currently Being Moderated
    Aug 22, 2012 11:00 PM   in reply to Rafael Paz2

    Hi Rafael,

     

         I want to call ".jsx" file(Adobe javascript) through JAVA... Is it possible?

     
    |
    Mark as:
  • Currently Being Moderated
    Mar 25, 2013 10:59 AM   in reply to Rafael Paz2

    Cenchen, there is sample Java code in Adobe's InDesign Server SDK to send a SOAP request to an InDesign Server process started up to serve SOAP requests on a particular port number. Part of what you send in the SOAP request as a parameter is a path to a .JSX file to execute (either from the requesting side, or on the server side). You can get back a JavaScript result from that script in your Java that issues the SOAP request.  Is what all you mean by wanting to call JavaScript from Java? Or is this something that you need to work also in InDesign desktop, not only the server verions?

     

    (Perhaps you have already discovered these answers since your posting.)

     

    There is also a load balancing scheme at least in CS6 using CORBA to make requests to the server.

     
    |
    Mark as:

More Like This

  • Retrieving data ...

Bookmarked By (0)

Answers + Points = Status

  • 10 points awarded for Correct Answers
  • 5 points awarded for Helpful Answers
  • 10,000+ points
  • 1,001-10,000 points
  • 501-1,000 points
  • 5-500 points