• Global community
    • Language:
      • Deutsch
      • English
      • Español
      • Français
      • Português
  • 日本語コミュニティ
    Dedicated community for Japanese speakers
  • 한국 커뮤니티
    Dedicated community for Korean speakers
Exit
0

Trouble getting curl applescript to execute in JSX

Community Expert ,
May 01, 2023 May 01, 2023

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

 

TOPICS
Actions and scripting , macOS , SDK

Views

152

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
no replies

Have something to add?

Join the conversation