I'm trying to calculate free space on Catalina. For prior versions of macOS, this piece from a script from Joshua Roskos' macOS Upgrade script works:
diskInfoPlist=$(/usr/sbin/diskutil info -plist /) ## 10.13.4 or later, diskutil info command output changes key from 'AvailableSpace' to 'Free Space' about disk space. freeSpace=$( /usr/libexec/PlistBuddy -c "Print :FreeSpace" /dev/stdin <<< "$diskInfoPlist" 2>/dev/null || /usr/libexec/PlistBuddy -c "Print :AvailableSpace" /dev/stdin <<< "$diskInfoPlist" 2>/dev/null )
But on Catalina, the result is "0" every time. The FreeSpace key that is generated by:
/usr/sbin/diskutil info -plist /
is always "0" on Catalina. What needs to be changed to get the correct value for FreeSpace?
Yes the code works in Big Sur, it is Bash. You would need to set it up to publish its results to make it into an EA.
I use it to report space to the user with a notification popup. Our Macs get a lot of the user space cleared out every day, but some of the students working on Movies can get a bit carried away and drop a serious amount of files on the hard drive. So they get warnings.