hey everybody. my sincere apologies for the delay. i got busy, and then i forgot.
Heres the workaround code to make a request to some website from illustrator (or theoretically, any other adobe software that doesnt offer a native solution). Warning, this was purpose built for my purposes quite a while ago and i havent bothered updating it since its working for me, so it likely needs tweaks and is definitely pretty messy. and it might have some dependencies from my own utilities, but those are generic and easy.
for my needs, i have a single URL and i just paste in an identifier (order number or something) to the end of the URL and that gives me the data i need. If you are accessing data from some public API that requires credentials to be sent with the payload, im not exactly sure how to manage that. but hopefully this mess helps point someone in the right direction.
//curl data from a specified url and return the data as an anonymous object
function curlData ( url, arg )
{
var result, status = "empty";;
var htmlRegex = /<html>/gmi;
var scriptText,
scriptFile,
executor,
killExecutor;
url = url + arg;
//variables for the local data stuff
var documentsPath = "path/to/documents/folder/"
var curlDataPath = documentsPath + "curlData/"
var curlDataFolder = new Folder( curlDataPath );
if ( !curlDataFolder.exists )
{
curlDataFolder.create();
}
var localDataFile = File( curlDataPath + "curlData.txt" );
//clear out the local data file..
//make sure we always start with an empty string
localDataFile.open( "w" );
localDataFile.write( "" );
localDataFile.close();
if ( $.os.match( "Windows" ) )
{
//write the bat file that will be
//used to execute the vbs script
writeVbsFile();
//define the executor script
//cscript.exe runs the .vbs file as though the CL is being used
scriptText = "cscript.exe \"";
//path to vbs script
scriptText += curlDataPath + "socket_xhttpRequest.vbs\"";
//vbs argument 1 = url
scriptText += " \"" + url + "\" \"";
//vbs argument 2 = path to curlData.txt file
scriptText += curlDataPath + "curlData.txt";
scriptFile = File( curlDataPath + "batFile.bat" );
writeScriptFile( scriptFile, scriptText )
executor = scriptFile;
}
else
{
scriptText = [
"do shell script ",
"\"curl \\\"" + url,
"\\\" > \\\"",
curlDataPath + "curlData.txt" + "\\\"\""
].join( "" );
/
scriptFile = File( curlDataPath + "curl_from_illustrator.scpt" );
writeScriptFile( scriptFile, scriptText );
executor = File( resourcePath + "curl_from_illustrator.app" );
var localExecutor = File( documentsPath + "curlData/curl_from_illustrator.app" );
if ( localExecutor.exists )
{
executor = localExecutor;
}
}
var maxExecutorCalls = 5;
var currentExecutorCalls = 0;
var checkDelay = 200;
var numberOfChecks = 200;
var totalChecks = 0;
var parseFailResults = 0;
do
{
totalChecks = 0;
//go get the data
executor.execute();
//check the data
for ( var a = 0; a < numberOfChecks && status !== "valid"; a++ )
{
if ( status != "valid" )
{
checkData()
totalChecks++;
}
else if ( status === "html" )
{
break;
}
$.sleep( checkDelay );
}
}
while ( status !== "valid" && status !== "html" && currentExecutorCalls < maxExecutorCalls );
//validate
if ( status === "html" || ( status === "empty" && parseFailResults.length ) )
{
alert( "The request to \"" + url + arg + "\" returned invalid data for " + arg );
}
return result;
function readDataFile ()
{
var file = localDataFile;
file.open( "r" );
var contents = file.read();
file.close();
return contents;
}
function writeScriptFile ( file, txt )
{
file.open( "w" );
file.write( txt );
file.close();
}
function writeVbsFile ()
{
//go to the network and copy the contents of the
//socket_xhttpRequest.vbs file
//this allows me to manage updates by updating a
//single central file, but each person will be executing
//their own copy, which should avoid someone being denied
//access because another person is already executing the file?
//central file
var srcFile = File( dataPath + "socket_xhttpRequest.vbs" );
//local file
var destFile = File( curlDataPath + "socket_xhttpRequest.vbs" );
//read the source file's contents
srcFile.open( "r" );
var srcContents = srcFile.read();
srcFile.close();
//write the contents to the local file
writeDatabase( destFile, srcContents );
}
function checkData ()
{
var contents = readDataFile();
if ( contents === "" )
{
status = "empty";
}
else if ( contents.match( htmlRegex ) )
{
status = "html";
}
else
{
try
{
result = JSON.parse( contents );
status = "valid";
}
catch ( e )
{
status = "parseFail";
parseFailResults++;
}
}
}
}
... View more