Skip to main content
brian_p_dts
Community Expert
Community Expert
May 2, 2023
Question

Trouble getting curl applescript to execute in JSX

  • May 2, 2023
  • 1 reply
  • 361 views

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();

 

This topic has been closed for replies.

1 reply

brian_p_dts
Community Expert
Community Expert
June 15, 2023

Bumping this back up to see if anyone has had issues executing Applescript from JSX routines lately. This code used to work, and the ASCode string works when I run it in the Applescript debugger. Maybe a permissions issue?