here is a script to give a full memory report. i wanted something to give me a report as useful and easy to read as the About This Mac box in OS 9. the script provides a simple rundown of:
- number of swapfiles
- number of pageouts
- free memory
- physical memory used by top 7 apps
- save it as a application, or save it as a compiled script and run it from the Script Menu.
- you can vary the number of applications reported by changing the number in the first line of the script.
- the script tries some kludgey workarounds to get application names from 'ps aux'. it assumes native non-system apps will reside in the Applications folder. your mileage may vary with regards to app names, but it should be better than those 'LaunchCFMApp' names in ProcessViewer. if anyone knows a better way to get app names, please post.
NOTE: This script has been substantially revised! It should now parse almost any possible application scheme correctly!
NOTE #2: Revised again!
set num to 9
global MRpid, MRrss, MRcom
do shell script "ls -l /var/vm/"
set c to number of paragraphs of result
set c to c - 1 as string
do shell script "vm_stat"
set r to result
set rt to return
set t to vmparse(r, 10) as string
set q to pageouts(t)
set dd to rt & "Swapfiles: " & c & rt
set dd to dd & "Pageouts: " & q
set dd to dd & rt & rt & rt
set a to vmparse(r, 1)
set t to vmmeg(a)
set dd to dd & "Free: " & t & " MB "
set dd to dd & rt & rt & rt
do shell script "ps aux -m -w -w -c"
set tres to result
set r to paragraphs 2 through (num + 2) of tres as list
set h to paragraph 1 of tres as string
set t to offset of "PID" in h
set MRpid to [(t - 2), (t + 2)]
set t to offset of "RSS" in h
set MRrss to [(t - 3), (t + 3)]
set t to offset of "COMMAND" in h
set MRcom to (t + 1)
repeat with c from 1 to num
set a to item c of r
set dd to dd & psmem(a) & " "
set dd to dd & psname(a) & rt
end repeat
display dialog dd & rt
on pageouts(a)
set a to a * 4
if a > 1024 then
set k to " MB"
set a to a / 1024
set a to a as real
else if a = 0 then
set k to ""
else
set k to " KB"
end if
set a to intnum(a)
return a & k
end pageouts
on vmparse(x, n)
set AppleScript's text item delimiters to {"."}
set y to text item n of x as string
set AppleScript's text item delimiters to {""}
set z to text items -1 through -8 of y as string
set a to lspace(z)
set a to a as integer
return a
end vmparse
on vmmeg(m)
set z to m / 256
set z to z as string
set a to intnum(z)
return a
end vmmeg
on psmem(r)
set d1 to item 1 of MRrss
set d2 to item 2 of MRrss
set AppleScript's text item delimiters to {""}
set t to text items d1 through d2 of r as string
set m to lspace(t)
set z to m / 1024
set z to intnum(z)
if z as number < 10 then set z to " " & z as string
return (z & " MB")
end psmem
on psname(r)
set AppleScript's text item delimiters to {""}
set pname to text items MRcom through -1 of r as string
if pname = "LaunchCFMApp" then
set d1 to item 1 of MRpid
set d2 to item 2 of MRpid
set pid to text items d1 through d2 of r as string
do shell script "ps " & pid & " -w -w"
set tres to result
set fo to offset of "COMMAND" in (paragraph 1 of tres)
set t to paragraph 2 of tres
set t to text items fo through -1 of t as string
set AppleScript's text item delimiters to {"/"}
set t to text item -1 of t as string
set tr to lspace(t)
set os to offset of tr in t
set pname to text items 1 through (os - 2) of t as string
end if
return pname
end psname
on lspace(t)
set AppleScript's text item delimiters to {" "}
set m to text item -1 of t
set AppleScript's text item delimiters to {""}
return m
end lspace
on intnum(x)
set x to x as string
set AppleScript's text item delimiters to {"."}
set z to text item 1 of x
set AppleScript's text item delimiters to {""}
return z
end intnum

