Copy link to clipboard
Copied
Hi all,
I am trying to curl images down from a website for a photoshop JSX application. If I type the following applescript into a .applescript file, then it works fine. However, I am throwing my 10 seconds elapsed error if I try to run the getMacImage function below. If I inspect the dl.app script that was created, it works fine. I've also tried saving as dl.applescript and it throws an error. The AS is here:
do shell script "curl -L -o '/Users/MyUserName/Desktop/test.jpg' 'https://www.google.co.in/intl/en_com/images/srpr/logo1w.png'"
Here is my jsx code:
var getMacImage = function(exporturl, assetFolderPath, fileName) {
try {
var ff = File(assetFolderPath + '/' + fileName);
if (!ff.exists) {
var curlCommand = "\"curl -L -o '" + ff.fsName + "' " + "'" + exporturl + "'";
var asCode = 'do shell script ' + curlCommand + '"';
var vbsf = new File(Folder.desktop + "/dl.applescript");
vbsf.open('w');
vbsf.write(asCode);
vbsf.close();
//alert(asCode);
vbsf.execute();
}
var c = 0;
while(!ff.exists) {
$.sleep(1);
c++;
if (c > 1000) {
throw new Error("More than 10 seconds to download image");
}
}
return ff;
}
catch(e) {
throw new Error("Error downloading asset from " + exporturl + ". " + e);
}
};
var unitTest = function() {
var afp = Folder.desktop.fsName;
var imgp = "https://www.google.co.in/intl/en_com/images/srpr/logo1w.png";
try {
var f = getMacImage(imgp, afp, "test1.jpg");
} catch(e) {
alert(e);
}
alert(f.exists);
}
unitTest();
Have something to add?