ExtendExtendScript/GetURL: now with a simple installer

Note 23-Jan-2023: Make sure to check out my novel approach to GetURL: making curl available in ExtendScript. Not just for InDesign – any Adobe app that supports ExtendScript can use this. More info here:

https://www.rorohiko.com/jsxgeturl

If all you want to get is an easy-to-use GetURL function for InDesign ExtendScript, I now have a simple installer to install ExtendExtendScript with the GetURL plug-in.

Version 1.0.4 was released on 16-Dec-2019 and supports InDesign 2020/macOS Catalina. This is a labor of love, and maintaining this tool is a substantial cost to Rorohiko. If this extension is useful to you, help us properly gauge how useful this is to you, and show us your level of interest and appreciation by donating via PayPal to [email protected]. If there is sufficient interest and appreciation, we’d be encouraged to keep on releasing updates!

Download it here: https://www.rorohiko.com/downloads/ExtendExtendScript.1.0.4.zip

Important: no warranties, neither expressed nor implied: use at your own risk.

You can find the source code and read more about ExtendExtendScript and how it works in some of my other posts: https://coppieters.nz/?p=133

If you’re not interested in how ExtendExtendScript works and all you want to do is access some URL from ExtendScript, this installer is for you.

The ExtendExtendScript extension is invisible. All it does is augment the InDesign ExtendScript environment with some new functions you can call.

It only works from a persistent ExtendScript engine; don’t run it from the ‘main’ engine, which is not persistent.

After installing this extension you can access a full-fledged HTTP/HTTPS downloader callable from ExtendScript, and you can write ExtendScript code like the following examples:

// Need to run in a persistent engine for callbacks to work
// Make sure to add JSInterface.jsx and json2.jsx

#targetengine TestSomewhere
#include "JSInterface.jsx"

function handleData(data) { 
 var fileURL = "~/Desktop/image.jpg";
 var file = new File(fileURL);
 file.encoding = "BINARY";
 file.open("w");
 file.write(data);
 file.close();
 alert("File downloaded to " + fileURL);
}

// Download an image file in ExtendScript over https
var url = "https://www.rorohiko.com/MagnetoGuides2-poster.jpg";

JSInterface.evalScript(
  "JSInterface.plugins.getURL(JSInterface.getData())", 
  url, 
  handleData);

Or

// Need to run in a persistent engine for callbacks to work
// Make sure to add JSInterface.jsx and json2.jsx

#targetengine TestSomewhere
#include "JSInterface.jsx"

// Some sample ExtendScript code. Fetch a URL over https and display 
// in an alert

function handleData(data) { 
 alert(data);
}

var url = "https://www.rorohiko.com/welcome.msg";

JSInterface.evalScript(
  "JSInterface.plugins.getURL(JSInterface.getData())", 
  url, 
  handleData);

This installer came about because I had built a more or less ‘standardized’ installer for installing the more recent software I wrote for Rorohiko. This installer does not rely on the ExManCmd command line tool, so it should be more robust. ExManCmd fails way too often, so I avoided using it.

And because I had the installer available anyway, I decided to roll off a copy just for ExtendExtendScript. Hope it proves useful!

9 thoughts on “ExtendExtendScript/GetURL: now with a simple installer”

  1. I’m integrating ExtendExtendScript into an application since I need the https support. Is there a recommended way of waiting for the result of the getURL to complete before continuing?

    Thanks again for this! This is saving me a lot of dev time.

  2. As to my previous question, I did not provide any details on what I am trying to do:

    I have queried a server:

    https://myserver.com?parms
    and the server is returning true or false which has been demonstrated using the sample code provided.

    Where I invoke the getURL call is where I want to wait until I get the result back in the callback.

    1. Hi Bill,

      I am not quite clear on what exactly you are doing. When you say ‘an application’ that seems to indicate an external stand-alone application, but I am not sure whether that is correct and whether that is relevant.

      Normally, what you do in JavaScript or ExtendScript (and this is how ExtendExtendScript does it too): you don’t wait. Instead you pass a callback into the asynchronous code, and that callback will be called once the asynchronous operation is finished. The calling code does not wait. It either goes on doing something else, or it terminates.

      If you are trying to code something like (pseudocode):

      DoSomething();
      var data = GetURL("farfaraway");
      DoSomethingWithData(data);

      That does not work. You need to approach this differently.
      DoSomething();
      GetURL("farfaraway", function(data) {
      DoSomethingWithData(data);
      });

      I.e. the main ‘thread’, if you will, ‘falls of the edge’ after the call to GetURL. And then once the GetURL is finished, it calls the callback, passes the data into it, and then we call DoSomethingWithData. This code does not wait.

  3. Hi,
    I’m calling an API that returns JSON which I then want to use in my script, so I do the following, which works, except that the JSON is UTF-8 but data is a string that is not UTF-8 decoded properly.

    I’m guessing this is because the GetURL is doing response.setEncoding(‘binary’), but I would like it to do response.setEncoding(‘utf8’). Now I have to manually UTF-8 decode the string. Is this something you have considered?

    function handleData(data) {
    doStuffWith(JSON.parse(data))
    }

    var url = “http://myapi”;

    JSInterface.evalScript(“JSInterface.plugins.getURL(JSInterface.getData())”, url, handleData);

    1. Hi Martin,

      The pre-packaged version that comes with the installer is as-is, but if you look at my other posts, all source code to GetURL is made available.

      It is based on a little utility module I built, called JSInterface, and the GetURL is no more than a sample plug-in for JSInterface. All source code is provided, and all you’d need to do is change the GetURL plug-in, or make a separate second plug-in.

      Option 1: dig into the source code, and modify the extension to match your needs. The GetURL plug-in is no more than a very small Node.js module, and the line you’re interested is around line 103:


      protocol.get(parsedURL, function(response) {

      response.setEncoding(‘binary’);

      function checkForCompletion() {

      Option 2: if you have time to wait it out, I think it is a good idea to make this configurable, and I could add some parameters to the GetURL so you could set the encoding from the calling code. Problem is: I am very busy, so it’ll be a fair while before I get round to that.

      Cheers,

      Kris

  4. I have worked out all my issues with the ExtendExtendScript and it is absolutely brilliant!!

    It does not seem to work with InDesign 2019. Is there something I need to do to make the ExtendExtendScript.1.0.3 work with InDesign 2019?

    1. Hi Bill,

      Probably all that is needed is to adjust the manifest file and then recompile the whole lot. I’ll try to do that some time, but it’s a labour of love, and takes a fair bit of my time, so my current for-pay customers take the front burner; I am fairly busy at the moment.

      The rest of the world is always on the move, so a recompile is never as simple as a push on the button: compilers are updated, signature files are replaced, files need little tweaks here and there; it always takes me a few hours to do.

  5. It is understood that paying customers are at the top of the priority queue.

    You have given me a clue on what the issue is and thanks for that insight. I’m going to try to fix by modifying the manifest and hope for the best :).

    If I get it working, I’ll send my changes so you can wrap it in the installer. Shall we continue this conversation via email?

    1. The changes to the manifest should be really simple: change

      <Host Name=”IDSN” Version=”[11.0,13.9]” />

      into

      <Host Name=”IDSN” Version=”[11.0,14.9]” />

      The real hassle is building an installer.

Comments are closed.