Monday, December 11, 2017

#1 2015-09-19 01:34:13 am

Titanium
Member
From:: ~/Desktop
Registered: 2005-08-22
Posts: 43
Website

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?


Applescript:

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


iMac 27" 3,4 Ghz - macOS High Sierra
https://www.titanium-software.fr

Offline

 

#2 2015-09-19 02:21:39 am

Shane Stanley
Member
From:: Australia
Registered: 2002-12-07
Posts: 5197

Re: Check disk space

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:

Applescript:

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


Shane Stanley <sstanley@myriad-com.com.au>
www.macosxautomation.com/applescript/apps/

Offline

 

#3 2015-09-26 05:30:47 am

Titanium
Member
From:: ~/Desktop
Registered: 2005-08-22
Posts: 43
Website

Re: Check disk space

Thanks Shane! cool


iMac 27" 3,4 Ghz - macOS High Sierra
https://www.titanium-software.fr

Offline

 

Board footer

Powered by FluxBB

RSS (new topics) RSS (active topics)