4 December 2008 @ 19:20Applescript File Downloader

Script EditorHere is a little Applescript that I threw together for the sole purpose of scheduling downloads of large files for times when it doesn’t matter if it slows my internet to a crawl (e.g. at night while I’m sleeping).

The cool thing about this script is that you can create an iCal even that has a repeating schedule and attach this script to the alarm options. Then every day at the scheduled time, the script will run and download any URLs that you have in the download list. The list is cleared after each downloaded item, so it won’t repeatedly download duplicate files.

Here is the script. You can either copy and paste the text below in Script Editor or click here: Applescript File Downloader

property DownloadFileList : "/Users/username/dl_list" -- this should be the full path to the download list which should have each URL on a separate line

set theuser to (do shell script "echo $USER")
set dlList to (do shell script ("cat \"" & DownloadFileList & "\""))

set listVariable to every paragraph of dlList
set the item_count to the number of items in listVariable
do shell script ("touch ~/.dltemp")
repeat with i from 1 to the (item_count - 0)
set dlURL to item i of listVariable
do shell script ("echo \"cd ~/Desktop/; curl -A \"Mozilla/4.0\" " & dlURL & " -O; \" >> \"/Users/" & theuser & "/.dltemp\"")
do shell script ("sed -i '' -e\"\\#" & dlURL & "#d\" \"" & DownloadFileList & "\"")
end repeat

set commands to (do shell script ("cat \"/Users/" & theuser & "/.dltemp\""))
tell application "Terminal"
do script ("" & commands & "")
end tell
do shell script ("rm \"/Users/" & theuser & "/.dltemp\"")

Here is a basic summary of the script. First, the complete path to your download list must be entered for the property DownloadFileList. This download list should have each url on a separate line and saved as plain text. Next, the script reads the download list, and then builds a temp file containing the commands to download the URLs one at a time, followed by their removal from the download list text file. Lastly, the temp file is removed.

It would have been much easier to have the script open a new Terminal window for each URL and download all URLs simultaneously, but I decided that it might be best to have each download finish faster than to slow them all down by downloading all at once.

There is a lot of room for improvement in this script, but it should provide some functionality and maybe spur some interesting Applescript ideas from you.

Shop for Applescript books

Be Sociable, Share!

by | Add a comment | Tags: , , , , ,
Posted in applescript | Link to this

Add a Comment

Show who you are with a Gravatar.

 

Sign up for PayPal and start accepting credit card payments instantly.

Staples Logo

Get fed!

rss icon subscribe to Geek stuff

rss icon Geek stuff in your inbox

Add the "Geek stuff" Google Gadget to your homepage

Add the "Daily Deals" Google Gadget to your homepage

Apparel

Search Amazon

Search Amazon.com
Search Amazon.co.uk

Recent Forum Topics

    Advert

    Web hosting by ICDSoft