|
|
My version...
First, I want to thank the author of the original script, it intrigued me enough to get off my butt and learn some applescript (I'm a UNIX programmer by day). With that said, I think you will find this version shorter and considerably faster than the original - first, because it doesn't need to make repeated calls to the shell, second because it uses math rather than string manipulation to round the results. Please tell me what you think! set MaxProcs to 5 set dstring to "OS X Virtual Memory Statistics:" & return set dstring to dstring & get_swap_info() set dstring to dstring & return & return & "Top " & MaxProcs & " Applications: " set dstring to dstring & get_big_procs(MaxProcs) display dialog dstring buttons {"Ok"} default button 1 -- Parses out the value of one line of output from vm_stat and -- returns it as a string in MB. on vmparse(x, n) -- extract the nth line of the output. set AppleScript's text item delimiters to {"."} set y to text item n of x as string -- Convert the # 4k pages to the nearest megabyte set AppleScript's text item delimiters to {" "} set a to (word -1 of y as integer) + 128 set a to (a - (a mod 256)) / 256 as integer return (a as string) & " MB" end vmparse -- Find out swap space stats and returns them as a string. on get_swap_info() -- get info about vm files do shell script "ls -l /var/vm" set r to result set c to number of paragraphs of r -- add up swap file sizes set t to 0 repeat with i from 2 to c set t to t + (word 6 of paragraph i of r) as integer end repeat -- round to the nearest megabyte. set t to t + 524288 set t to (t - (t mod 1048576)) / 1048576 as integer set o to " Total Swap: " & t & " MB in " & c - 1 & " files" do shell script "vm_stat" set r to result set o to o & return & " Used Swap: " & vmparse(r, 10) set o to o & return & " Free RAM : " & vmparse(r, 1) as string return o end get_swap_info
rest of the script
The comment form truncated the script. Here's the last part: -- Returns a list of the largest num applications on get_big_procs(num) do shell script "ps auxmww" set r to paragraphs 2 through (num + 2) of result as list set o to "" repeat with c from 1 to num set e to item c of r -- get size rounded to nearest MB set vsz to ((word 6 of e) as integer) + 512 set vsz to ((vsz - (vsz mod 1024)) / 1024) as integer set o to o & return & " " & vsz & " MB " -- extract the process name set AppleScript's text item delimiters to {""} set ao to offset of "/" in e set a to (text items ao through -1 of e) as string -- if the name contains ".app", truncate the name there. set ao to offset of ".app" in a if (ao is not 0) then set a to (text items 1 through (ao - 1)) of a as string -- extract the executable name from the process name. set AppleScript's text item delimiters to {"/"} set a to text item -1 of a set o to o & a end repeat return o end get_big_procs
Max No of App Details?
Is there anyway to increase the number of Top "n" apps? Even though I modified the variable used for the loop, it appears (for me at least) that the maximum is 7. Any ideas?
Max No of App Details?
I think the problem is that there is some upper limit to the # of characters you can send to a dialog. Try this: replace the top portion of the script (everything above 'on vmparse(x,n)') with this code:
This fragment will display one dialog if you ask for 5 or fewer apps, and two dialogs if you want more than 5. I'm also working on a version that handles UNIX command line arguments correctly.
Max No of App Details?
rather than fragment into 2 dialogs, get rid of the text section headers. that gives room for a few more apps. using my layout, i can fit 9 - 11 depending on length of the app names.
Max No of App Details?
heh. No sympathy from me - I'm using a 256mb iBook.
My version...
much more elegant code. using word & paragraph - who woulda thunk it?
-psn
Yeah - basically those are UNIX command line arguments. I'm not sure how to deal with them because there's no easy way to tell where the application name stops and the arguments begin, when the application name is allowed to have spaces in it. I'm pondering it though; we'll see what I can come up with.
-psn
just filter out " -psn" the same way you filter out ".app"
-psn
yup, I added this just after the filer for .app
-psn
Well, I want a general version that will kill any command line args. They almost always have a dash in front, and a space, so I think I have a solution. |
SearchFrom our Sponsor...Latest Mountain Lion HintsWhat's New:HintsNo new hintsComments last 2 daysLinks last 2 weeksNo recent new linksWhat's New in the Forums?
Hints by TopicNews from Macworld
From Our Sponsors |
|
Copyright © 2014 IDG Consumer & SMB (Privacy Policy) Contact Us All trademarks and copyrights on this page are owned by their respective owners. |
Visit other IDG sites: |
|
|
|
Created this page in 0.10 seconds |
|