Because my app can fill up a hard disk pretty fast I have been using a check for free space for a longer time. Today I got a disk space warning that less than 10% free space was left. But the numbers are totally wrong:
I tried again with a new project and the value I get for free space is 14859243520:
dim f as FolderItem = SpecialFolder.Desktop
dim theVolumeInformation as VolumeInformationMBS = f.VolumeInformationMBS
dim FreeBytes as Int64 = theVolumeInformation.Freebytes
Device Identifier: disk3s3
Device Node: /dev/disk3s3
Whole: No
Part of Whole: disk3
Volume Name: Recovery
Mounted: No
Partition Type: 41504653-0000-11AA-AA11-00306543ECAC
File System Personality: APFS
Type (Bundle): apfs
Name (User Visible): APFS
Owners: Disabled
OS Can Be Installed: No
Booter Disk: disk3s2
Recovery Disk: disk3s3
Media Type: Generic
Protocol: Apple Fabric
SMART Status: Verified
Volume UUID: 74E4D4CF-5397-40E5-9C01-76048AA34864
Disk / Partition UUID: 74E4D4CF-5397-40E5-9C01-76048AA34864
Apple calls this purgeable space, the first thing to try “Turn it off and on again”. It will then perform some cleaning duties on shutdown (or it might be startup).
I’m not using TimeMachine on the computer. The computer does turning off by kernel panic every week. I also can’t expect my users to know about the internal workings of macOS.
I’ve done a bit of searching on StackOverflow. But there were only questions and no answers. How does DaisyDisk identify the purgeable space.
It uses NSURL resource keys to obtain volume information. If you use the Ohanaware App Kit, I can provide you with code, but I’m sure Christian will be able to look at this and tell you how it’s done using his plugin.
The below code will return a human readable representation of permanent FREE space on a volume, using the Ohanaware App Kit.
Dim outValue, error as integer
Dim nurl as integer = volume( 0 ).NSURL
if NSURLGetResourceValue( nurl, outvalue, "NSURLVolumeAvailableCapacityForImportantUsageKey", error ) then
freeSpace = formatBytes( xojoValue( outValue ) )
end if
The below code will return a human readable representation of temporary FREE space on a volume, using the Ohanaware App Kit.
Dim outValue, error as integer
Dim nurl as integer = volume( 0 ).NSURL
if NSURLGetResourceValue( nurl, outvalue, "NSURLVolumeAvailableCapacityForOpportunisticUsageKey", error ) then
freeSpace = formatBytes( xojoValue( outValue ) )
end if
@Christian_Schmitz : what are the equivalents in the MBS plugin? I only see disk size.
Dim n As New NSURLMBS(SpecialFolder.Desktop)
dim value as Variant
dim error as NSErrorMBS
Dim result As Boolean = n.getResourceValue(value, n.NSURLVolumeAvailableCapacityKey, error)
I’ll add NSURLVolumeAvailableCapacityForImportantUsageKey, NSURLVolumeAvailableCapacityForOpportunisticUsageKey and a few others today for next pre-release.
But are you also shutting the computer off by hand? A clean shut down would not only benefit the shut down process, but may also clean more things when the computer starts next time.