1

I try to download files to a AFP drive but always have "Warning: Failed to create the file /Volumes/home/Downloads: Is a directory "

But the last command work fine tell application "Finder" to open ("/Volumes/home/Downloads" as POSIX file)

set theFileURL to the clipboard
set {TID, AppleScript's text item delimiters} to {AppleScript's text item delimiters, "/"}
set theFile to text item -1 of theFileURL
set AppleScript's text item delimiters to TID

set theFilePath to "/Volumes/home/Downloads"
try
    do shell script "curl " & quoted form of theFileURL & " -o " & quoted form of POSIX path of theFilePath
    display dialog "The download is finished!" buttons {"OK"} default button 1 with icon note giving up after 5
on error theError
    display dialog "Error downloading the file:" & return & theFile & return & return & theError buttons {"OK"} default button 1 with icon 0 giving up after 5
end try


tell application "Finder" to open ("/Volumes/home/Downloads" as POSIX file)

in the same kind of script, I'm also to download torrent to my Synology Download Station if anyone have a clue.

1

The curl command in the do shell script command is malformed. The -o option expects a filename or a fully qualified pathname filename not just a path like what the variable theFilePath contains. See the man page for curl, in a Terminal type man curl and press enter and then scroll down to -o, --output <file> where it states: Write output to <file> instead of stdout.

So your do shell script command should look like:

do shell script "curl " & quoted form of theFileURL & " -o " & quoted form of POSIX path of (theFilePath & "/" & theFile)

If you include the / (slash) at the end of the value you set for the theFilePath variable e.g. set theFilePath to "/Volumes/home/Downloads/" you can eliminate & "/" from the do shell script command, which would then look like:

do shell script "curl " & quoted form of theFileURL & " -o " & quoted form of POSIX path of (theFilePath & theFile)

Additionally, since you have already set theFilePath you can use that in your tell application "Finder" statement, e.g:

tell application "Finder" to open theFilePath as POSIX file

If you want Finder to trigger the opening of the file, and depending on how you set theFilePath (with or without a /) use one of the following appropriately:

tell application "Finder" to open (theFilePath & "/" & theFile) as POSIX file
tell application "Finder" to open (theFilePath & theFile) as POSIX file

The AppleScript code shown below contains both forms of the theFilePath variable and the do shell script command along with two version of the tell application "Finder" statement with one set commented out with the leading -- (double-dash).

set theFileURL to the clipboard
set {TID, AppleScript's text item delimiters} to {AppleScript's text item delimiters, "/"}
set theFile to text item -1 of theFileURL
set AppleScript's text item delimiters to TID

-- set theFilePath to "/Volumes/home/Downloads"
set theFilePath to "/Volumes/home/Downloads/"

try
    -- do shell script "curl " & quoted form of theFileURL & " -o " & quoted form of POSIX path of (theFilePath & "/" & theFile)

    do shell script "curl " & quoted form of theFileURL & " -o " & quoted form of POSIX path of (theFilePath & theFile)

    display dialog "The download is finished!" buttons {"OK"} default button 1 with icon note giving up after 5
on error theError
    display dialog "Error downloading the file:" & return & theFile & return & return & theError buttons {"OK"} default button 1 with icon 0 giving up after 5
end try

tell application "Finder" to open theFilePath as POSIX file
-- tell application "Finder" to open (theFilePath & "/" & theFile) as POSIX file
-- tell application "Finder" to open (theFilePath & theFile) as POSIX file
  • @KevinCork, Sorry I left out some parentheses, in the do shell script command, so I added them to theFilePath & theFile and theFilePath & "/" & theFile e.g (theFilePath & theFile) and (theFilePath & "/" & theFile) so if the theFile variable filename has spaces it's handled properly. – user3439894 Jan 19 '16 at 19:40
  • for some reason it's only downloading the first bytes of the file. – Kevin Jan 19 '16 at 20:11
  • @KevinCork, Can you provide the URL so I can test it. Also, if you use curl directly in a Terminal does it download only part of the file? – user3439894 Jan 19 '16 at 20:17
  • sure, I just testing with a random URL get.videolan.org/vlc/2.2.1/macosx/vlc-2.2.1.dmg – Kevin Jan 19 '16 at 20:18
  • @KevinCork, That file bombs out for me too in both AppleScript and using curl in aTerminal so it's not an AppleScript issue. Other files work for me fine. – user3439894 Jan 19 '16 at 20:26

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .