Roberto Aloi
Roberto Aloi

Reputation: 30985

How can I download a file using AppleScript?

Something like:

set the file_tgt to (path to downloads as string) as file specification
    set file_src to "http://my_file.png"
    tell application "URL Access Scripting"
        download file_src to file_tgt
    end tell
  1. How do I get the path to the default downloads folder for the user?
  2. AppleScript doesn't like the path conversion. How can I fix that?

Upvotes: 4

Views: 7584

Answers (2)

Ashok
Ashok

Reputation: 6244

To download a collection of files hosted in a directory using applescript and shell script -

set counter to 0
repeat 36 times
    do shell script "curl -f 'http://stage.omatics.com/Images/Devices/Devices/" & counter & ".png' -o ~/Desktop/" & counter & ".png"
    set counter to counter + 10
    delay 2
end repeat

This will download these 36 files

http://stage.omatics.com/Images/Devices/Devices/0.png
http://stage.omatics.com/Images/Devices/Devices/10.png
http://stage.omatics.com/Images/Devices/Devices/20.png
--
--
http://stage.omatics.com/Images/Devices/Devices/350.png

at your desktop.

Hope this helps.

Upvotes: 0

Roberto Aloi
Roberto Aloi

Reputation: 30985

I found the solution myself:

  1. Use "path to downloads folder"
  2. set the file_tgt to (path to downloads folder as string) & "file.png"

Upvotes: 3

Related Questions