ExtendExtendScript/GetURL: now with a simple installer

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.

Download it here: https://www.rorohiko.com/downloads/ExtendExtendScript.1.0.2.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!

3 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.

Leave a Reply

Your email address will not be published. Required fields are marked *