Howdy all,
This is one I’m having a bit of a problem with. I know how a progress bar is supposed to be done… progress one out of progress two sort of thing.
What I’m trying to do is get the status of a file transfer. Basically, you’ll have a folder full of stuff being transfered to a disk. Obviously, this can take some time… in the range of 5-10 mins in some cases. So instead of using that indeterminate bar, I’d like to use the progress bar.
So here’s what I understand on these things so far.
1- They update based on the information you give them
2- They have to be in a repeat loop to update (?)
3- You need variables to define a percentage of things completed.
Ok…
So I guess I need to be able to get the total size of the items being transferred, which I THINK I know how to do, I need to get how much as been transfered, which I don’t know how to do, and I need to wrap it up in a loop, which I don’t know how to do without repeating the transfer over and over.
Basically, I know what i need, but I’m in the dark as to how to implent these things in an updating progress bar. I’ve searched around, which is how I came about most of the info I have up there, but I’m not too sure as to how to apply it.
I think the indicator itself would be something like this…
property var1 : ""
property var2 : ""
set var1 to (get size of folder theFolder) --the total amount being transferred
set var2 to 0
repeat until var1 is equal to var2
--set var2 to ?? --amount transfered total
set content of progress indicator "progind" of window "main" to (var2/var1)
end repeat
Something like that? The hardest part I’m stuck with is how to get the total amount transferred, and continuing to update it.
-Parrot
You know how much is to be transferred up front. You can measure the size of the container it’s filling. You run an indeterminate bar until a few percent of the transfer flows in (noted by the increase in size of the container). Note the time taken. Now you can calculate the percentage in place (or the estimated time to completion), and set the progress bar accordingly. Cycle through your loop measuring size (or time, if that’s what you want to watch), and adjust the progress bar periodically. Go back to indeterminate when the job is almost done, and wait for the end. Dismiss.
Hi Parrothead,
I am replying only to the part quoted below, not to the entirety of your post.
To get the total amount transferred and continue to update it should be quite simple. Set up one variable, say “totalTransferred” outside your repeat loop and initialize it to zero. Then, inside the repeat loop create another variable, say “amount_thisTransfer”, and set it to the current amount transferred during the current instance of the loop. Then, simply increment totalTransferred using the formula:
totalTransferred = totalTransferred + amount_Transferred.
Everytime through the loop, the variable totalTransferred will be updated and should accumulate everytime through the repeat loop.
If you wish to calculate the percentage of completed file transfer, create another variable, say for example “percent_completion” (initialize outside the repeat loop to zero), that stores the tranferred value in %. You need to know the grand total amount to be transferred (another variable, say “cumulativeTransfer” for instance). Inside the repeat loop, after incrementing the totalTransferred variable, you may then calculate like this:
percent_completion = ((totalTranferred/cumulativeTransfer) x 100) (you can express it in coded terms as I am just trying to present it simply here).
Then you go ahead and record this percent_completion in a text field beside your progress bar to show how much had already been transferred.
Hope the above helps.
Good luck!
archseed
Hi Parrothead,
Oops!
A little correction in the formula (though I am sure you could spot this typo easily).
The updating formula inside the repeat loop should be:
totalTransferred = totalTransferred + amount_thisTransfer
Good luck, just the same.
archseed
Basically, what I think i’ve got is something like…
set grandtotal to (get size of folder theFolder)
set totaltransferred to 0
duplicate every item of theFolder to theDisk with replacing
repeat until grandtotal = totaltransferred
set thisTransfer to --how to get current amount transferred?
set totaltransferred to (totaltransferred + thisTransfer)
set content of progress indicator "progind" of window "main" to totaltransferred
end repeat
Is that the general idea? I’m still lost as to how to actually get how much has been transferred in one instance of a loop, though.
As for adams idea. I like that, it sounds a bit simpler, but the thing is that lets say this disk has a 2mb/sec transfer rate. A few of these files are small things, like text files, ect. When these are transferred, that bogs things down a bit, which might really mess with the time. How do you propose this is avoided?
If you’re putting the moved stuff in a folder on theDisk, then you can get it’s size before you start:
tell application "Finder" to set initSize to size of alias "theDisk:Backup:"
– don’t know what theDisk is, but getting the size of an external volume is iffy.
Then something along these lines:
tell application "Finder"
set grandtotal to (get size of folder theFolder)
set initSize to size of "theDisk:Backup:"
duplicate every item of theFolder to theDisk with replacing
set was to 0
set isNow to size of "theDisk:Backup:"
repeat while isNow ≠was
set was to size of "theDisk:Backup:"
delay 1
set isNow to size of "theDisk:Backup:"
set Pct to (grandtotal - isNow) / grandtotal --- make this the fraction that the PB wants to see
-- set progress bar to pct
end repeat
end tell
An after thought. If using the Finder to get size doesn’t work because the Finder is busy with the transfer, then:
set was/isNow to size of (info for) theReceivingFolder, perhaps in a handler outside the Finder.