I have a fairly simple script I run from the Finder’s AppleScript menu that displays a dialog of the size of the trash. In leopard (and possibly Tiger) the dialog would occasionally say: “The trash contains missing value bytes.” All I had to do was run the script a second time and I’d get the size. (Curiously, I trap the “size of trash” line in a try block. When there’s a missing value, AS doesn’t report an error.)
Since installing Snow Leopard, it seems the “missing value” is sticky. No matter how many times I run the script, it reports missing value. However if I manually do a get-info on the trash, the script will then work.
This board has similar postings going back years describing similar problems, which makes me wonder about the insidiousness of this “bug”
Here’s my script, does it work for anyone else with SL:
on trimNum(aBigNumber)
if aBigNumber > 1.0E+9 then
return (aBigNumber div 1.0E+9) & "GB"
else if aBigNumber > 1000000 then
return (aBigNumber div 1000000) & "MB"
else if aBigNumber > 1000 then
return (aBigNumber div 1000) & "KB"
else
return aBigNumber & " bytes"
end if
end trimNum
tell application "Finder"
try
set trashSize to the size of the trash
on error
set trashSize to the size of the trash
end try
set trashString to my trimNum(trashSize)
display dialog ("The trash contains " & trashString) buttons {"OK"} default button 1
end tell
I guess an alternative would be to do a do shell script “du ” ??
on trimNum(aBigNumber)
if aBigNumber > 1.0E+9 then
return (aBigNumber div 1.0E+9) & "GB"
else if aBigNumber > 1000000 then
return (aBigNumber div 1000000) & "MB"
else if aBigNumber > 1000 then
return (aBigNumber div 1000) & "KB"
else
return aBigNumber & " bytes"
end if
end trimNum
set trashBin to path to trash as alias
try
set trashSize to the size of (info for (trashBin))
on error
set trashSize to the size of (info for (trashBin))
end try
set trashString to my trimNum(trashSize)
display dialog ("The trash contains " & trashString) buttons {"OK"} default button 1
I don’t know, if it works also in Snow Leopard, but this is a reliable way to gather the size
on trimNum(aBigNumber)
if aBigNumber > 1.0E+9 then
return (aBigNumber div 1.0E+9) & "GB"
else if aBigNumber > 1000000 then
return (aBigNumber div 1000000) & "MB"
else if aBigNumber > 1000 then
return (aBigNumber div 1000) & "KB"
else
return aBigNumber & " bytes"
end if
end trimNum
tell application "System Events"
repeat until (size of trash is not missing value)
delay 0.5
end repeat
set trashString to my trimNum(size of trash)
end tell
display dialog ("The trash contains " & trashString) buttons {"OK"} default button 1
Thanks mark hunte; I was in such a “Finder” mode I didn’t think of alternatives. But catchesides is right; the old way should work. If you try to get the properties of anything, you get a lot of missing values:
There is one potential advantage with using “path to” and “info for” – you don’t need a tell block. And I’m guessing that whatever error I might have thought I could trap with the try block doesn’t exist, making it unnecessary (right?)
This seems to work:
on trimNum(aBigNumber)
if aBigNumber > 1.0E+9 then
return (aBigNumber div 1.0E+9) & "GB"
else if aBigNumber > 1000000 then
return (aBigNumber div 1000000) & "MB"
else if aBigNumber > 1000 then
return (aBigNumber div 1000) & "KB"
else
return aBigNumber & " bytes"
end if
end trimNum
set trashBin to path to trash
set trashSize to size of (info for trashBin)
set trashString to trimNum(trashSize)
display dialog ("The trash contains " & trashString) buttons {"OK"} default button 1