Skip to content

Instantly share code, notes, and snippets.

@mericson
Created September 10, 2013 14:13
Show Gist options
  • Star 11 You must be signed in to star a gist
  • Fork 5 You must be signed in to fork a gist
  • Save mericson/6509997 to your computer and use it in GitHub Desktop.
Save mericson/6509997 to your computer and use it in GitHub Desktop.
Loads data from a URL in Adobe Illustrator! (Uses Bridge behind the scenes)
var doc = app.activeDocument;
var docPath = doc.path;
function loadUrl(url, callback) {
var bt = new BridgeTalk();
bt.target = 'bridge' ;
var s = '';
s += "if ( !ExternalObject.webaccesslib ) {\n";
s += " ExternalObject.webaccesslib = new ExternalObject('lib:webaccesslib');\n";
s += "}\n";
s += "var html = '';\n";
s += "var http = new HttpConnection('" + url + "') ; \n";
s += "http.response = html;\n";
s += "http.execute() ;\n";
s += "http.response;\n";
bt.body = s;
bt.onResult = function( inBT ) { callback( null, inBT.body ); };
bt.onError = function( inBT ) { callback( 1, null ); };
bt.send( 50 );
}
function done( err, data ) {
if ( err ) {
$.writeln( 'FAILED' );
} else {
$.writeln( data );
}
}
loadUrl( 'http://www.nytimes.com', done );
true;
@circleb
Copy link

circleb commented Sep 10, 2020

Both of them were very painful, but this one actually seemed slightly better.

@daluu
Copy link

daluu commented Sep 13, 2020

Well, obviously this one may be better in terms of speed due to async behavior & parallel processing perhaps. The other one meant for when you don't want to deal with "synchronizing" asynchronous code or don't have anything else to do while waiting on data from loading URL.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment