Welcome to the MacNN Forums.

If this is your first visit, be sure to check out the FAQ by clicking the link above. You may have to register before you can post: click the register link above to proceed. To start viewing messages, select the forum that you want to visit from the selection below.

You are here: MacNN Forums > Software - Troubleshooting and Discussion > Developer Center > Applescript: Getting the CPU and RAM level?

Applescript: Getting the CPU and RAM level?
Thread Tools
Addicted to MacNN
Join Date: Sep 2000
Status: Offline
Reply With Quote
Feb 24, 2003, 09:43 AM
 
Anyone know how using applescript to get the CPU level, and free/consumed ram?

I know there is some shell integration in AppleScript, but have failed to do this successfully yet.
I always use protection when fscking my Mac... Do you?
     
Professional Poster
Join Date: Oct 1999
Location: :ИOITAↃO⅃
Status: Offline
Reply With Quote
Feb 25, 2003, 09:08 AM
 
Call this as a shell script and it will get what you want. It should be easy to parse the string that it prints out from within Applescript.

Don't forget that in Applescript, you'll need to escape the quotes with \" and \':

Code:
top -l 1 1 | awk '/CPU usage/ {printf("user\t%s\nsys\t%s\nidle\t%s\n",$8,$10,$12)} /PhysMem/ {printf("wired\t%s\nactive\t%s\ninactive\t%s\nused\t%s\nfree\t%s\n",$2,$4, $6, $8, $10, $12)}'
You can try pasting it into the Terminal to see how it works. It just takes the output from top and feeds it through awk, which is a very handy tool for extracting text.
     
Professional Poster
Join Date: Oct 2001
Location: London
Status: Offline
Reply With Quote
Feb 25, 2003, 09:44 AM
 
You can use the Standard Additions' "system attribute" event.

It is a wrapper to Gestalt. which will allow you to get all sorts of info about the machine.

e.g.

Code:
get system attribute "cput"
then (if you have the Dev tools) look through gestalt.h for the return values. here's a bit:

/*
The gestaltNativeCPUtype ('cput') selector can be used to determine the
native CPU type for all Macs running System 7.5 or later.

The 'cput' selector is not available when running System 7.0 (or earlier)
on most 68K machines. If 'cput' is not available, then the 'proc' selector
should be used to determine the processor type.

An application should always try the 'cput' selector first. This is because,
on PowerPC machines, the 'proc' selector will reflect the CPU type of the
emulator's "virtual processor" rather than the native CPU type.

The values specified below are accurate. Prior versions of the Gestalt
interface file contained values that were off by one.

The Quadra 840AV and the Quadra 660AV contain a bug in the ROM code that
causes the 'cput' selector to respond with the value 5. This behavior
occurs only when running System 7.1. System 7.5 fixes the bug by replacing
the faulty 'cput' selector function with the correct one.

The gestaltNativeCPUfamily ('cpuf') selector can be used to determine the
general family the native CPU is in. This can be helpful for determing how
blitters and things should be written. In general, it is smarter to use this
selector (when available) than gestaltNativeCPUtype since newer processors
in the same family can be handled without revising your code.

gestaltNativeCPUfamily uses the same results as gestaltNativeCPUtype, but
will only return certain CPU values.
*/
enum {
gestaltNativeCPUtype = 'cput', /* Native CPU type */
gestaltNativeCPUfamily = 'cpuf', /* Native CPU family */
gestaltCPU68000 = 0, /* Various 68k CPUs... */
gestaltCPU68010 = 1,
gestaltCPU68020 = 2,
gestaltCPU68030 = 3,
gestaltCPU68040 = 4,
gestaltCPU601 = 0x0101, /* IBM 601 */
gestaltCPU603 = 0x0103,
gestaltCPU604 = 0x0104,
gestaltCPU603e = 0x0106,
gestaltCPU603ev = 0x0107,
gestaltCPU750 = 0x0108, /* Also 740 - "G3" */
gestaltCPU604e = 0x0109,
gestaltCPU604ev = 0x010A, /* Mach 5, 250Mhz and up */
gestaltCPUG4 = 0x010C, /* Max */
gestaltCPUG47450 = 0x0110 /* Vger , Altivec */
};

enum {
gestaltCPUApollo = 0x0111, /* Apollo , Altivec */
gestaltCPU750FX = 0x0120 /* Sahara,G3 like thing */
};

enum {
/* x86 CPUs all start with 'i' in the high nybble */
gestaltCPU486 = 'i486',
gestaltCPUPentium = 'i586',
gestaltCPUPentiumPro = 'i5pr',
gestaltCPUPentiumII = 'i5ii',
gestaltCPUX86 = 'ixxx'
};

     
Addicted to MacNN
Join Date: Mar 2000
Location: London, UK
Status: Offline
Reply With Quote
Feb 25, 2003, 11:02 AM
 
I didn't think most gestalts worked in OS X?
     
Professional Poster
Join Date: Oct 2001
Location: London
Status: Offline
Reply With Quote
Feb 25, 2003, 11:17 AM
 
Originally posted by Angus_D:
I didn't think most gestalts worked in OS X?
Most of the important ones do.

More importantly - I just re-read the original post - and realised that I completely mis-read it first time round - You want the workload - not the proc type - Doh!
     
Addicted to MacNN
Join Date: Sep 2000
Status: Offline
Reply With Quote
Feb 25, 2003, 12:15 PM
 
ultimately I want

x = processor concumption
y = free ram
z = used ram
I always use protection when fscking my Mac... Do you?
     
Mac Elite
Join Date: Dec 2001
Location: Atlanta, GA, USA
Status: Offline
Reply With Quote
Feb 26, 2003, 02:26 PM
 
Originally posted by macvillage.net:
ultimately I want

x = processor concumption
y = free ram
z = used ram
Code:
x = top -l1 | grep "CPU usage" | awk '{print $8}' y = top -l1 | grep "PhysMem" | awk '{print $10}' z = top -l1 | grep "PhysMem" | awk '{print $8}'
You can wrap shell commands pretty easily and get what you want.

Too bad OSX doesn't have a /proc/cpuinfo like Linux.
(Last edited by Arkham_c; Feb 27, 2003 at 10:55 AM. )
Mac Pro 2x 2.66 GHz Dual core, Apple TV 160GB, two Windows XP PCs
     
Dedicated MacNNer
Join Date: Nov 2000
Status: Offline
Reply With Quote
Feb 27, 2003, 12:23 AM
 
It's /proc/cpuinfo, but it doesn't contain that sort of information anyways. It contains information about the physical chip.

A combination /proc/loadavg and /proc/meminfo would give you the info you need.
     
   
Thread Tools
Forum Links
Forum Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts
BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On
Top
Privacy Policy
All times are GMT -5. The time now is 08:49 PM.
All contents of these forums © 1995-2011 MacNN. All rights reserved.
Branding + Design: www.gesamtbild.com
vBulletin v.3.8.7 © 2000-2011, Jelsoft Enterprises Ltd., Content Relevant URLs by vBSEO 3.3.2