Submit Hint Search The Forums LinksStatsPollsHeadlinesRSS
14,000 hints and counting!

A script to update a hard drive's free space value Desktop
I found out something annoying about the hard drive icon on the desktop: if you have the Show Item Info option enabled (in View -> Show View Options), then the amount of free space in the info line never gets updated by itself. You either have to quit the Finder, reboot, or log off and on to make it refresh).

I read in some internet forum that copying any file to the top level of the drive (/) would make the available space figure refresh. So what I did was create an empty file in my Documents folder (touch space.txt in the Terminal), and then using crontab and a small script, copy this file every five minutes to /.

Here is the script, which I named freespace_updater.sh:
#!/bin/sh
rm /space.txt
cp /Users/martin/Documents/space.txt /
And the associated crontab entry:
martin$ crontab -l
0,5,10,15,20,25,30,35,40,45,50,55 * * * * /usr/bin/freespace_updater.sh
I know this is very dirty, but at least it refreshes my free space info every five minutes.

[robg adds: I tested this, and was surprised to find that it's true -- if you have hard drives visible on the desktop, and use the Show Item Info option, the free space value never seems to update. But copying and deleting a file from the root level forced an instant update. I would switch the order of commands in the script (cp first, then rm), since that way, nothing is left at the top level, and it seemed to work just as well when I was testing it. What didn't work, somewhat oddly, was touching a file at the top level; it seems an actual copy operation is required to force the update.

If you have multiple volumes, you'd probably need the script to copy a dummy file to the top level of each of them.]
    •    
  • Currently 3.50 / 5
  You rated: 5 / 5 (4 votes cast)
 
[8,816 views]  

A script to update a hard drive's free space value | 11 comments | Create New Account
Click here to return to the 'A script to update a hard drive's free space value' hint
The following comments are owned by whoever posted them. This site is not responsible for what they say.
A script to update a hard drive's free space value
Authored by: bakalite on Sep 01, '05 10:56:46AM

Actually I've found that emptying the trash will update the free space indicator. So usually I just empty the trash, which is not a bad idea anyway if you want to know how much space you have available. If it's empty, I just select any file on my desktop (there are usually some small text files there), hit command-D to make a copy, drag it to the trash and empty it. I know this is a little more cumbersome, but it doesn't spin up your HD every 5 mn.



[ Reply to This | # ]
A script to update a hard drive's free space value
Authored by: papplegate on Sep 01, '05 11:09:47AM

Why don't you just open Activity Monitor, and click the Disk Usage Tab? It never has a problem updating.
Paul



[ Reply to This | # ]
A script to update a hard drive's free space value
Authored by: Mike Dillingham on Sep 01, '05 12:08:10PM

Just wanted to point out that your crontab entry could be greatly simplified by using "*/5". This means execute every 5 minutes. The entry would then become:

*/5 * * * * /usr/bin/freespace_updater.sh

Do a "man 5 crontab" to see the specifics of this format.



[ Reply to This | # ]
applescript too
Authored by: SOX on Sep 01, '05 01:53:42PM

The finder appears to cache a lot of things that get out of synch.

For example, write an applescript to report the owner and file permissions on a file the finder sees. run it. Change the permissions from the command line. re-run your script. It will report the OLD values. THis is really a security hole since it means an applescript cant reliably determine if a file is owned by root.

I think you can force it to update by calling the finder's get info, but I'm not sure.



[ Reply to This | # ]
ONe problem
Authored by: kaltekar on Sep 01, '05 02:40:46PM

I see one big problem with doing this. You are writting to the HDD every five minutes, which means that unless you put your drive to sleep in under five minutes your drives will never spin down to save power. This is can be a real problem on laptops were the HDD is one of the largest power consumers in the machine. Not to mention it causes unneeded wear and tear on the drives mechanics. Just a little something to keep in mind.



[ Reply to This | # ]
A script to update a hard drive's free space value
Authored by: nickdynamite on Sep 01, '05 03:41:08PM

or you could just relaunch the finder...

takes 1-3 seconds on my machine...



[ Reply to This | # ]
A script to update a hard drive's free space value
Authored by: arvindb21 on Sep 01, '05 04:58:21PM

I don't see this problem on Tiger. If I make a copy of a file when the info page of the HD is open, the free space gets updated correctly. Is this a pre Tiger issue?



[ Reply to This | # ]
A script to update a hard drive's free space value
Authored by: BMarsh on Sep 02, '05 12:26:33AM

not the "Get Info" free space, this is the Finder "Show View Options" while the desktop is selected, there is a "Show Item Info" checkbox, that will display below the name of any connected Volumes the amount of free space...

and this bug has existed since Apple introduced the feature in 10.3



[ Reply to This | # ]
A script to update a hard drive's free space value
Authored by: Cerberus on Sep 01, '05 10:09:04PM

Use this script to place the space.txt file on every local drive and then (per rob's excelent suggestion) remove it.

#!/bin/sh
HD_ROOT_PATH=$(df -l | grep -i dev | awk ' { print $6}')
#echo -e "Root Path = "$HD_ROOT_PATH
for i in $HD_ROOT_PATH
do
if [ -d $1 ] ; then
#echo -e "Found a dir @ "$i
cp /Users/Shared/space.txt $i
rm $i/space.txt
fi
done


As you may be able to see I put the space.txt file in /Users/Shared. I think this is a better place for it as then this script does not rely on any personal accounts to copy a file in (just in case your account goes wonky etc.)

P.S. I left in some echo's so you all can 'watch' what it is doing if you so desire.



[ Reply to This | # ]
A script to update a hard drive's free space value
Authored by: Cerberus on Sep 02, '05 11:29:21AM

OK I just found out that this script works on any locally mounted device that does not cotnain a space in the name. Anyone have a suggestion for fixing this? This is the only limitation that this sctipt has now...



[ Reply to This | # ]
A script to update a hard drive's free space value
Authored by: Cerberus on Sep 02, '05 11:41:23AM
here is the final code (works much better now) should work under every circumstance:

#!/bin/sh
HD_ROOT_PATH=$(df -l | grep dev | cut -b 54-)
#echo -e "Root Path = "$HD_ROOT_PATH
for i in $HD_ROOT_PATH
do
 if [ -d "$i" ] ; then
  #echo -e "Found a dir @ $i"
   cp /Users/Shared/space.txt "$i"
   rm "$i"/space.txt
 fi
done


[ Reply to This | # ]