System Events vs Finder File Size Calculation Discrepancies in 10.6.x

I’m writing a Service with an AppleScript doing the work. Among other things, the AppleScript has to calculate the total size in bytes of the items (files and/or folders) selected in a Finder folder window. The size is then used for further actions, such as burning a DVD or copying to a USB key. The size calculation is done using the System Events. This is a simple example of the size calculation:


tell application "Finder"
	set selectionList to selection as alias list
	tell application "System Events"
		set x to 0
		repeat with thisItem in selectionList
			set x to x + (physical size of disk item (thisItem as text))
		end repeat
	end tell
	set SizeMB to (round ((x / (1000 ^ 2)) * 10)) / 10 & " MB"
	display dialog "The Size is " & x & " Bytes, or " & SizeMB
end tell

Note note that I cannot use the Finder instead of System Events to calculate the sizes, because the Finder expects all windows to be formatted to calculate the sizes and the size values be already there. This is not my default window format.

The results of the System Events calculations are generally identical with the Finder calculations. However, this is not true in OS X 10.6.x with any HFS+ compressed items, where the System Events (and du) gives much smaller sizes than the Finder. There are huge discrepancies. For instance, the Calculator v 4.5.3 is 2.2 vs 4.0 MB, or the DVD Player v5.2 is 2.8 vs 32.3 MB. It is as if the System Events (and du) gives the actual compressed size on the disk, while the Finder gives the uncompressed size.

The items burned to DVDs or copied to USB keys have to be also readable on earlier OS X and even on PC, therefore they must be uncompressed.

Is there any way to make System Events (or du) to report the uncompressed size?

Or alternatively, to force the Finder to calculate the size of the selected items regardless of the window “calculate size” setting and status?

Finder in 10.6 uses base 10 to calculate file size instead of the usual base 2.

http://blog.tweefari.com/apple-mac-os-x-106-snow-leopard-uses-base-10

I’m pretty sure you could convert from one to the other… it is stupid, I’ll give you that.

Model: MacBook
AppleScript: 2.3
Browser: Google Chrome
Operating System: Mac OS X (10.6)

Thanks, but that is not really the issue here. The problem I have is that, applescript in 10.6 reports different file sizes for Apple apps depending on using System Events or Finder to get the file size.

From another forum
http://reviews.cnet.com/8301-13727_7-20014841-263.html?tag=mncol;title
http://reviews.cnet.com/8301-13727_7-20015100-263.html
it is clear that System Events (and du) report the hfs+ compressed size, while the Finder reports the uncompressed size.

Because the Finder sizes are only available when the window prefs are set to calculate the sizes and the calculation is completed, it is not a good choice to use in a script.

What I need, is a modified script using System Events (if it’s possible) or better, a “do shell script” to calculate and report both, the compressed and uncompressed sizes. I assume that a “do shell script” is possible since the second link points to a few unix commands. Unfortunately, my unix “skills” are non-existant. Can anybody help?