Looks like no one’s replied in a while. To start the conversation again, simply ask a new question.

Set path to folder? (Save cURL to folder) [Applescript]

I need to save a cURled file to a certain spot. I'm really bad at this, so I'm probably missing something obvious. here is my script:


set username to short user name of (system info)

set targetpath to POSIX path of (path to "Macintosh HD:Users:" & username & ":Library:Application\\ Support:minecraft:bin:minecraft.jar ")

set this_URL to "http://assets.minecraft.net/1_9-pre6/minecraft_server.jar"

(do shell script "curl -L " & this_URL & " -o " & POSIX path of the destination with administrator privileges) & targetpath

Posted on Mar 12, 2013 11:03 PM

Reply
2 replies

Mar 13, 2013 1:42 PM in response to Boboonski

For a start, you're going about this the wrong way.


This is the wrong way to determine your destination location:


set username to short user name of (system info)

set targetpath to POSIX path of (path to "Macintosh HD:Users:" & username & ":Library:Application\\ Support:minecraft:bin:minecraft.jar ")


A much better way would be:


set targetPath to POSIX path of ((path to library folder from user domain as text) & "minecraft:bin:minecraft.jar")


By using 'path to library folder' you can find the localized, current user's library folder - that is, you don't ned to know the user's name, or the language of their OS, or the name of their hard drive, or any other details beyond the subdirectories.


Secondly, your url command is a little hard to decode due to the multiple levels of commands and parameters. For example, the 'with administrator priviliges is associated with the 'do shell script' but it looks like it's part of your curl. You already coerce targetPath to a POSIX path, so there's no need to do it again. Finally, the parameters are also wrong - the URL has to be the last parameter to curl.

I recommend a divide-and-conquer approach:


set targetPath to POSIX path of ((path to library folder from user domain as text) & "minecraft:bin:minecraft.jar")

set this_URL to "http://assets.minecraft.net/1_9-pre6/minecraft_server.jar"

set curl_command to "/usr/bin/curl -o " & targetPath & " " & this_URL

do shell scriptcurl_command with administrator privileges


By breaking the script into separate statements that define your variables, build the curl command, and then execute it, it's easier to read (and debug).

Set path to folder? (Save cURL to folder) [Applescript]

Welcome to Apple Support Community
A forum where Apple customers help each other with their products. Get started with your Apple ID.