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

Trouble getting curl applescript to execute in JSX

Community Expert ,
May 01, 2023 May 01, 2023

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
297
Translate
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
Adobe
Community Expert ,
Jun 15, 2023 Jun 15, 2023
LATEST

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? 

Translate
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