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

Disk space usage summary via AppleScript Desktop
This tiny Applescript saves me the trouble of having to always go to the terminal and enter "df -k" to see my disk space usage.

It shows you the amount of space used for every volume (partition) and also the amount of disk space used for VM. Unfortunately, the Finder does not get notified of changes in VM, but the figures are still pretty usefull, especially if you don't have enough space on your boot volume.

Copy and paste the text into the Script Editor, save it as an application, and simply drop it into either ~/Library/Scripts or /Library/Scripts. (And download the Menuscript addition.

Read the rest of the article for the script...

tell application "Finder"
set bootname to (the startup disk) as string
-- fix this if your vm is somewhere else than the default
-- eg "Volumes:swap_partition_name:vm:swapfile"
set vmspacename to ((the startup disk) as string) & ":private:var:vm:swapfile"

set myList to list disks
set outList to {}
set allFree to 0
set allSpace to 0
set outString to ""
repeat with i in myList
set diskName to (i as string)
try
set freeSpace to round (the (free space of disk diskName) / 1024 / 1024)
set totalSpace to round (the (capacity of disk diskName) / 1024 / 1024)
set allFree to allFree + freeSpace
set allSpace to allSpace + totalSpace

set outList to outList & {{diskName, freeSpace, totalSpace}}
set outString to outString & diskName & ": " & freeSpace & " MB, " &
(round (100 * freeSpace / totalSpace)) & " % free" & return
end try
end repeat
set outList to outList & {{"All", allFree, allSpace}}
set outString to outString & return & "All" & ": " & allFree & " MB, " &
(round (100 * allFree / allSpace)) & " % free" & return & return
repeat with i from 0 to 8
try
get the size of file (vmspacename & i)
on error
-- we fail when no swapfileX is present -> we have X files *
set vm to (i) * (the size of file (vmspacename & "0")) / (1000 * 1000)
exit repeat
end try
end repeat
set vm to (vm as string) & " MB Virtual Memory in use"
end tell
display dialog outString & vm
    •    
  • Currently 5.00 / 5
  • 1
  • 2
  • 3
  • 4
  • 5
  (2 votes cast)
 
[11,363 views]  

Disk space usage summary via AppleScript | 6 comments | Create New Account
Click here to return to the 'Disk space usage summary via AppleScript' hint
The following comments are owned by whoever posted them. This site is not responsible for what they say.
Won't Compile
Authored by: wuf810 on Jan 31, '02 05:41:20PM

Well I'm sure its handy but I can't get it to compile.



[ Reply to This | # ]
Worked here...
Authored by: robg on Jan 31, '02 06:25:52PM

What errors are you getting? I just literally selected all the above text, pasted into Script Editor, and said "Check Syntax" then run.

If you've moved your swap partition, you'll need to fix the second line of the script, otherwise you'll get a runtime error.

-rob.



[ Reply to This | # ]
Worked here...
Authored by: wuf810 on Feb 01, '02 05:53:21AM

"Expected Expression but found unknown token".

I haven't moved my Swap file but I do have my OS X installed on a separate volume on my hard disk.



[ Reply to This | # ]
Worked here...
Authored by: wuf810 on Feb 01, '02 06:00:45AM

Just checked and the errors are generated by these two lines

set outString to outString & diskName & ": " & freeSpace & " MB, " &

set outString to outString & return & "All" & ": " & allFree & " MB, " &



[ Reply to This | # ]
Give this a go...
Authored by: pmccann on Feb 01, '02 07:26:14AM

For each of those two lines you could simply try deleting the final symbol and recreating it (in script editor) using option-return. Could be that they're not surviving the paste operation, though as others have posted, worked "out of the box" for me.

Alternatively, just delete the line continuation symbol ("") and (for each of the two lines concerned) join the given line with the following line in the script.

Hope that works (as the script is very nice, and surprisingly quick!),
Paul



[ Reply to This | # ]
Give this a go...
Authored by: wuf810 on Feb 01, '02 03:10:11PM

Paul thank you. That got it going! An you're right its quick and really useful. Thanks again.



[ Reply to This | # ]