Notify users when their disk space is running low

Hi all,

I'm an administrator of about 100 Apple macs and an OS X server and generally speaking, problems are pretty easy to fix. There is just one major problem I'm always having and its simple to fix, which is that when Users run out of home disk space (only 600MB each) applications start crashing (understandably). The problem is that users don't actively watch their free disk space and when things start going wrong, I'll come along and point out that they need to delete some things and it'll start working again.

What I'm having trouble with (because I'm an absolute beginner) is making an AppleScript (or whatever would be best) to watch for when their home space is getting full (with 20MB free space) it'll pop up and say "don't trouble the technician, delete some files!" (or something along those lines)

So, here's what I have (pretty pathetic)

tell application "Finder"
set freeSpace to (free space of (get startup disk)) div 1024 div 1024
end tell

Is their a way of finding disk space of a Home Drive (which is on a network drive on the server)

What I'd like is to say
tell application "Finder"
set freeSpace to (free space of (get home)) div 1024 div 1024
end tell

It tells me "can't get free space of folder "stephenl"" (my home folder)

Could anyone please help

PowerG4's G5's and XServer Dual G4 2GB ram, Mac OS X (10.4.4)

Posted on Sep 25, 2007 6:37 AM

Reply
8 replies
Sort By: 

Sep 25, 2007 7:04 PM in response to stephen leach

--I'm sure there are several ways to do what you want; here's one that works on an individual computer. If necessary, suitable changes should be possible for server situations, but someone else will have to jump in on that. Copy this to Script Editor, make suitable modifications, then save it as an application; be certain "Startup Screen" isn't checked. Either have the user start it when the computer is started up, or place it in the log-in items (System Peferences) so that happens automatically.

set message_ to "Stephen! Don't trouble the technician, delete some files!" -- modify to suit

set MinAllowFS to 20 -- set this to the available disk space you want to trigger one or more of the responses. MB doesn't have to be specified if everything is in MB (max. possible space, etc.), otherwise some adjustments will have to made to the script. To TEST the script, set the number above what you know the available space could be.

repeat --(However often you want to check free space)
delay 5 --that's 5 seconds; if you think every 10 minutes is often enough to check, make that 600; or make it 0 and the script will repeat essentially in the time it takes to run, which is about 2.5 seconds on my machine

try
set bootDiskInfo to do shell script "diskutil list | grep 'stephen'" -- this gets information for all disks, and then finds the line pertaining to disk 'stephen' (change as necessary)

set bootDiskID to last word of bootDiskInfo -- that last word is the identifier for the disk you're after

set FSinfo to do shell script "diskutil info " & bootDiskID & " | grep 'Free Space'" -- similar to the above command, getting the free space for the boot disk.

set ActFS to word 3 of FSinfo -- word 3 is the numerical value of the free space, irrespective of the multiplier (KB, MB, GB etc.); as stated previously, there will have to changes to the script if the spaces range amongst multipliers.

--Pick one or more of the following responses by removing the comment ("--")

if ActFS < MinAllowFS then beep 3

--if ActFS < MinAllowFS then display dialog message_

--if ActFS < MinAllowFS then say "[[rate 180]]" & message_--[here's a link on using speech: http://www.blankreb.com/studioarticles.php?ID=3
end try
end repeat
Reply

Sep 26, 2007 3:53 AM in response to stephen leach

--PLEASE USE THIS MODIFIED VERSION OF THE SCRIPT POSTED EARLIER. IT INCLUDES AN "IDLE HANDLER" WHICH ALLOWS THE FINAL APPLICATION TO BE QUIT NORMALLY AND PREVENTS ISSUES AT SHUTDOWN OF THE COMPUTER.

--MOST OF THE COMMENTS IN THE ORIGINAL SUBMISSION STILL APPLY. THE REPEAT RATE IS NOW SET NEAR THE END OF THE SCRIPT, AS SHOWN


--AGAIN, SAVE THE SCRIPT AS AN APPLICATION, BUT SELECT "STAY OPEN" (ONLY).


-- ****BEGIN SCRIPT
idle
on idle
set message_ to "Stephen! Don't trouble the technician, delete some files!"
set MinAllowFS to 20
try
set bootDiskInfo to do shell script "diskutil list | grep 'stephen'"
set bootDiskID to last word of bootDiskInfo
set FSinfo to do shell script "diskutil info " & bootDiskID & " | grep 'Free Space'"
set ActFS to word 3 of FSinfo

--Pick one or more of the following responses by removing the comment ("")

--if ActFS < MinAllowFS then beep 3

--if ActFS < MinAllowFS then display dialog message_

if ActFS < MinAllowFS then say "[[rate 180]]" & message_
end try
return 10 --<< Here's where you set the repeat rate in seconds
end idle
-- ****END SCRIPT
Reply

Sep 26, 2007 4:09 AM in response to stephen leach

There still seem to be some formatting issues with posts. In my post of a few minutes ago:

1) ... by removing the comment ("") should be ... by removing the comment ("--")

2) For the spoken message option, the rate should be expressed as [[rate 180]] surrounded by double quotes, but it shows up in the post with single brackets. If there is further confusion on this, go to the link I cited in my first post.

(Hope this correction posts correctly)
Reply

Oct 3, 2007 8:23 AM in response to osimp

Wow, thanks for that. I tried it out and just about did exactly what I wanted. Just a few tweaks.

The diskutil list | grep 'stephen' is perfect for local accounts but doesn't take into account network drives which we're using here. With a bit of poking about I came across:

"df -k | grep '/Users HD/User Homes'"

which lists all things mounted on the computer, of which one is "/Users HD/User Homes" where their home drive is. I found the 5th word which is their disk usage and it all worked. I had problems with the use of the "loop" but your later post worked absolutely perfectly.

So now I've got it so when anyone logs in it loads up this program which analyse's their disk space. Only problem now is to get them to read the message and do something about it.

I really appreciate your help on this, and now I've had a taste of setting up scripts, I'm going to start making scripts for my hole job, which will soon be fully automated.

Many Thanks

Stephen
Reply

This thread has been closed by the system or the community team. You may vote for any posts you find helpful, or search the Community for additional answers.

Notify users when their disk space is running low

Welcome to Apple Support Community
A forum where Apple customers help each other with their products. Get started with your Apple Account.