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?