argv has asked for the wisdom of the Perl Monks concerning the following question:

Advanced warning: this has nothing to do with cgi or anything web-related.

I am a heavy user of photoshop and other adobe products, and they are beginning a heavy push towards javascript as a customization mechanism for users to do various things like build new UI elements, call lower-level functions within the app, etc. And it's not just adobe apps doing this--I'm finding many other products are also putting javascript engines in the middle of their UI and API layers.

Because I have a far more extensive library of perl apps that I've written (and acquired from cpan) over the years, I would love to somehow make use of them. I'm not familiar with javascript enough to know whether (or how) I can "link" to perl, or have any connection whatsoever to it from inside a javascript engine. Clearly, if Adobe wanted to, they could provide one as part of their particular library of javascript functions, but I doubt they have done such a thing (nothing of the sort is documented).

So, I wonder if there's a way to do it myself, or if anyone has sufficient knowledge or experience with it that could point me in the right direction.

Replies are listed 'Best First'.
Re: calling perl functions from javascript
by john_oshea (Priest) on Jan 27, 2007 at 12:46 UTC

    Application.doScript appears, at first glance, to be a possibility. From the documentation (for InDesign CS2, but I'd imagine Photoshop to be similar):

        Runs a script. The script can be either a file or a string.

    The obvious downside to this is that it will only run AppleScript, JavaScript or VBScript scripts, not any arbitrary language. That said, you could probably hack something together on a Mac by calling an AppleScript which then called your Perl code directly. Passing data back and forth would probably be best described as 'icky', but it should be possible. I'm not sure if VBScript has similar external access for Windows systems.

    Hope that helps.

Re: calling perl functions from javascript
by Anonymous Monk on Jan 27, 2007 at 07:10 UTC
Re: calling perl functions from javascript
by jonadab (Parson) on Jan 27, 2007 at 17:09 UTC

    This is really a Javascript question. Presumably you would call Perl code in the same way you would call any other external application or script, whether it's a shell script, Python, a compiled binary, or what have you. I would ask a Javascript guru how to do this. My knowledge of Javascript can safely be described as "limited".

    We could tell you how to use Javascript code from within a Perl application... but that's the reverse of what you want to do.


    Sanity? Oh, yeah, I've got all kinds of sanity. In fact, I've developed whole new kinds of sanity. You can just call me "Mister Sanity". Why, I've got so much sanity it's driving me crazy.
Re: calling perl functions from javascript
by Burak (Chaplain) on Jan 27, 2007 at 11:31 UTC
    Not sure about Mac systems, but you can control Photoshop with Perl through Win32::OLE under Windows...
    A reply falls below the community's threshold of quality. You may see it by logging in.
Re: calling perl functions from javascript
by geekphilosopher (Friar) on Jan 27, 2007 at 18:07 UTC
    My company uses JavaScript in our browser-based interface to talk to Perl on the server (AJAX). If those applications that you are using are able to provide HTTP Request objects, and you can set up a local server, then that may be a solution for you. No idea if that's feasible, as I've never used JS in any context outside of a browser.