intermittent "type real" error

Hi all,

I have the following snippet of code within my script:

tell application "Finder"
	if folderStatus is equal to true then
		set folderSize to size of folder FolderToBeBackedUp
		set legibleSize to ((folderSize / (1024 ^ 3) + 0.5) as integer)
		set folderPath to POSIX path of (FolderToBeBackedUp as alias)
		if legibleSize > 8 then
			set errormsg to {errormsg, "The backup did not run because the size of the folder selected for backup, \"" & FolderToBeBackedUp & "\", is " & legibleSize & " GB and too large for a typical writable DVD." & return & return} as text
			my WriteLog(errormsg)
			set BackupSuccess to false
		end if
	end if
end tell

When I run the script the first time, I get the error "“can’t make missing value into type real”. If I then run it a second time without changing anything, the script runs and doesn’t complain (although it hangs later when I invoke hdiutil. Any idea as to what I might be doing wrong?

Hi,

the problem is, it takes some time to calculate the size of folder with a hugh amount of files.
A solution is to use a repeat loop, which checks whether the size (is not missing value and) doesn’t increase any more.

So will Applescript only set the value of folderSize once the calculation is complete, or will that value keep changing as it continues to do the arithmetic? I would hope it’d be the former, but your response makes it sound like it’s the latter!

Here’s my stab at adding the necessary code, but I’m not sure if I’m doing it right (since, even if the code turns out to be syntatically correct, I’m not sure my “testsize is equal to foldersize” method will work, since it depeds on how quickly the variable value gets updated):

if folderStatus is equal to true then
       set folderSize to size of folder FolderToBeBackedUp
       set testSize to 1
       repeat
           if folderSize is not missing value then
              if testSize is equal to folderSize then
                   exit repeat
              else 
                   set testSize to folderSize
              end if
          end if
       set legibleSize to ((folderSize / (1024 ^ 3) + 0.5) as integer)

Suggestions welcome!

Sorry, forget my stupid sentence about increasing size

this should work:

set f to path to home folder
tell application "Finder"
	repeat until size of f is not missing value
		delay 0.5
	end repeat
	set s to size of f
end tell
s

Thanks much! That seems to have done the trick.