I've made this download script a few days ago:
do shell script "curl -L -o ~/Desktop/file.dmg 'https://download.mozilla.org/?product=firefox-27.0.1-SSL&os=osx&lang=en-GB' > ~/Desktop/status 2>&1 &"
set fileSize to 0
set curTransferred to 0
set curProgress to 0
repeat until curProgress = "100"
try
set lastLine to paragraph -1 of (do shell script "cat ~/Desktop/status")
set curProgress to word 1 of lastLine
set fileSize to word 2 of lastLine
set curTransferred to word 4 of lastLine
tell me
display dialog "Downloading. Please wait...
Status: " & curTransferred & " of " & fileSize & " (" & curProgress & "%)" buttons {"Refresh", "cancel"} giving up after 4
if the button returned of the result is "cancel" then return
end tell
on error
display dialog "Something went wrong when downloading the file. If you would like to restart the download then press the button 'Retry'" buttons {"Quit", "Retry"} with icon 0
end try
end repeat
It works, but I still have got some problems (3 to be exact) Problem number one:
Is there a way to display ONLY the CurTransferred, FileSize and Curprogress without making a new window every 4 seconds to display/refresh the (new) information?
Problem number two:
Is there a way in applescript to make a kind of 'Pause' button (in this script)? So when clicking pause the download will stop and a new dialog will open with a 'Continue' or 'Start' button?
Problem number three:
Is there a way to change the ~/Desktop/file.dmg
to a code like this one: set downloadlocation to (choose folder)
and then something like: path to (downloadlocation)
in the script instead of ~/Desktop/file.dmg
If you know an answer to one of the problems (or all) then don't hesitate to answer this question(s)!
Thanks for reading,
Jort
PS: maybe also a check for Internet Connection would be cool but not necessary.
Problem number one:
No
Problem number two:
No
Problem number three
set downloadLocation to choose folder with prompt "choose download location"
do shell script "curl -L -o " & quoted form of (POSIX path of downloadLocation & "file.dmg") & " 'https://download.mozilla.org/?product=firefox-27.0.1-SSL&os=osx&lang=en-GB' > ~/Desktop/status 2>&1 &"
Problems one and two are not solvable with pure AppleScript because AS works synchronously in a single thread. As the shell script is set not to wait for completion, there is no way to control the progress except to read the output from the status file.
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.