Search code examples
shellcurlapplescript

Applescript: Curl command was working, now I get a missing token error


I had the following Applescript code that was previously working, but now I get the error: Expected “given”, “in”, “of”, expression, “with”, “without”, other parameter name, etc. but found unknown token. Is it some kind of permissions issue?

do shell script 'curl -L -o "/Users/myUserName/Desktop/newimagename.jpg" "https://somewebsite.com/files/gallery/1676041915.jpg"'

I was expecting the image to be downloaded to my desktop with its new name. I have confirmed the website url to the jpg is valid.


Solution

  • You have problems with quotes here. The outer quotes are for the do shell script command of the AppleScript language (more precisely, of its Standard additions) and they must be double ("). And the single quotes (') are for shell commands, which is the curl command too.

    That is, you need to swap them:

    do shell script "curl -L -o '/Users/myUserName/Desktop/newimagename.jpg' 'https://somewebsite.com/files/gallery/1676041915.jpg'"
    

    Other, and the better choice is using quoted form of for the provided paths.

    set outputPath to "/Users/myUserName/Desktop/newimagename.jpg"
    set sourceURL to "https://somewebsite.com/files/gallery/1676041915.jpg"
    
    do shell script "curl -L -o " & quoted form of outputPath & space & quoted form of sourceURL