Check disk space

Hello,

In my application ASOC, I added a test disk space routine. It works on my iMac but not with some users. I don’t found where is the problem.

The following code is it correct?

    on runCheckDiskSpace()
        try
            set usedpercent to text 1 thru -2 of (do shell script "df / | tail -n 1 | awk '{print $5}'")
            if usedpercent is greater than or equal to "80" then
                display alert "Startup disk almost full." message "You need to make more space available on the disk by deleting files."
            end if
        end try
    end runCheckDiskSpace

Thanks and sorry for my bad english. :cool:

As a practical matter, having a fixed percentage free is not required – it’s generally more important to have a certain amount free, regardless of the size of the volume.

Either of these two handlers will return the available free space, plus the total disk capacity for a volume:

on freeAndTotalSpace(volumePath)
	set theNSURL to current application's class "NSURL"'s fileURLWithPath:volumePath
	set {theResult, availSize} to theNSURL's getResourceValue:(reference) forKey:(current application's NSURLVolumeAvailableCapacityKey) |error|:(missing value)
	set {theResult, totalSize} to theNSURL's getResourceValue:(reference) forKey:(current application's NSURLVolumeTotalCapacityKey) |error|:(missing value)
	set theArray to current application's NSArray's arrayWithArray:{availSize, totalSize} -- in case numbers exceed AS integer capacity
	return theArray as list
end freeAndTotalSpace

on freeAndTotalSpace2(volumePath)
	set fileAttr to current application's NSFileManager's defaultManager()'s attributesOfFileSystemForPath:volumePath |error|:(missing value)
	set availSize to (fileAttr's objectForKey:(current application's NSFileSystemFreeSize))
	set totalSize to (fileAttr's objectForKey:(current application's NSFileSystemSize))
	set theArray to current application's NSArray's arrayWithArray:{availSize, totalSize} -- in case numbers exceed AS integer capacity
	return theArray as list
end freeAndTotalSpace2

Thanks Shane! :cool: