Skip to content

Instantly share code, notes, and snippets.

@ff6347
Forked from mericson/loadUrl.jsx
Created April 11, 2017 06:41
Show Gist options
  • Select an option

  • Save ff6347/55baa2185bb6e77c7c386e40fd700c5b to your computer and use it in GitHub Desktop.

Select an option

Save ff6347/55baa2185bb6e77c7c386e40fd700c5b 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;
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment