System call to check (free, inactive, wired, active) memory

Does anyone know how to implement an (Applescript/Shell script) runtime check to see what the memory status is…?

Not the most elegant, but this works using Activity Monitor. I would prefer to strip output out of top, but given the interactive nature of it, I haven’t quite figured out how to do that yet.

activate application "Activity Monitor"
tell application "System Events"
	tell process "Activity Monitor"
		click radio button "System Memory" of tab group 1 of window "Activity Monitor"
		set {used, free, "", "", "", wired, "", "", inactive, active, "", "", "", vmsize, ""} to get value of every static text of tab group 1 of window "Activity Monitor"
	end tell
end tell
tell application "Activity Monitor" to quit

Take a single sample with top and extract the physical memory overview line. Pipe the result to awk if you want to manipulate the output further.

top -Rl 1 | grep ^PhysMem

As usual, I wonder why the OP needs to know such information. Could you elaborate a bit on what you wish to do?

/slaps head

The grepping & awk I was kosher with. The getting Top to direct to stdout was the problem I was running into as you know a top | grep ^PhysMem won’t work as top stays in interactive mode.