I’ve been looking at the forum and searched alot on google, but I’m still a bit lost and can’t find much docu on this,
I got a script which downloads a file to a temp folder inside my application, then moves the file and clears the folder.
and I’m using cURL to download the file, what i need is to show some infomation in my application about the download
i have a process spinner which is running while the file is being downloaded, but i would like to show the size change in
the application, can somebody so kind to point me in the right direction, or might drop a eks…
You can try something like this. Feed it the path to the downloading file
and it checks every second (change to desired time) and exits when the
file’s size is no longer changing.
Cheers,
Craig
set file_path to quoted form of "/Users/craig/Desktop/log.txt"
script FileSize
property current_size : 0
on check_file_size(file_path)
set file_size to do shell script "du " & file_path & " | awk '/[0-9]+/ {print $1}'"
if current_size = file_size then
--use this to test
--display dialog "Complete " & current_size & space & file_size
return
else
set current_size to file_size
--insert your update text here
delay 1
check_file_size(file_path)
end if
end check_file_size
end script
FileSize's check_file_size(file_path)
Thanks alot for this, I’ll try an see if I can get it to work in my interface, biggest problem is i dont know what size the file have i download.
and the idea was to fetch that infomation from the site first so i have that info before the download starts. which gives me something to “match” up for
You do not need to know the file size. As the file is downloading it’s size
is changing constantly. When the size stops changing the two variables
will match. Then you will know the file size and that it has finished
downloading.
One thing I noticed in the script is that I forgot to reset the current_size
to zero after the size match. The following corrects that.
Cheers,
Craig
set file_path to quoted form of "/Users/craig/Desktop/log.txt"
script FileSize
property current_size : 0
on check_file_size(file_path)
set file_size to do shell script "du " & file_path & " | awk '/[0-9]+/ {print $1}'"
if current_size = file_size then
set current_size to 0
return
else
set current_size to file_size
--insert your update text here
delay 1
check_file_size(file_path)
end if
end check_file_size
end script
FileSize's check_file_size(file_path)
Oy Craig I almot forgot about this, been working on so much last days i havn’t had the time to test this to end, but it sure looks like Im about to be there, so thank you very much…