-
-
Save mericson/6509997 to your computer and use it in GitHub Desktop.
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; |
For synchronous version without callbacks, see https://gist.github.com/daluu/2d9dec72d0863f9ff5a7
Just curious what sort of data would you download to IA from the web, and what would you do with it? Thanks
@daluu This script is working nicely, but it's taking at least 30 seconds per call. Is that normal? I'm running the latest version of both Bridge and InDesign.
@csuebele I've got a simple PHP script that formats data from my database and servers it to a webpage, the data is dynamic, based on URL parameters.
@circleb, which script are you referring to? My synchronous port or this original async version? I'm wondering if the issue is version specific to AI and Bridge. I don't recall how long it took for me, but it was "bearable".
I haven't touched AI and Bridge for several years.
Both of them were very painful, but this one actually seemed slightly better.
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.
Thanks for sharing. And this script snippet would be run from Illustrator?