Re: Extraction of Information from Apple System Profiler
Re: Extraction of Information from Apple System Profiler
- Subject: Re: Extraction of Information from Apple System Profiler
- From: Nathan Day <email@hidden>
- Date: Thu, 20 Dec 2001 23:03:38 +1030
This is pretty much cut straight out out of a one of my own projects
with some small changes, you have to include Carbon. I haven't found a
way to do this sort of thing yet using straight Cocoa. Email me if you
can not get it to work. I have a whole set of classes for compiling and
executing apple scripts including sending apple events to them which I
could send to you if you want.
+ (id)compileExecuteString:(NSString *) aString
{
OSAID theResultID;
AEDesc theResultDesc = { typeNull, NULL },
theScriptDesc = { typeNull, NULL };
id theResultObject = nil;
if( (AECreateDesc( typeChar, [aString cString], [aString
cStringLength], &theScriptDesc) == noErr) && (OSACompileExecute
( [AppleScriptObject OSAComponent], &theScriptDesc, kOSANullScript,
kOSAModeNull, &theResultID) == noErr ) )
{
if( OSACoerceToDesc( [AppleScriptObject OSAComponent],
theResultID, typeWildCard, kOSAModeNull, &theResultDesc ) == noErr )
{
if( theResultDesc.descriptorType == typeChar )
{
theResultObject = [NSString stringWithAEDesc:&theResultDesc];
AEDisposeDesc( &theResultDesc );
}
}
AEDisposeDesc( &theScriptDesc );
if( theResultID != kOSANullScript )
OSADispose( [AppleScriptObject OSAComponent], theResultID );
}
return theResultObject;
}
+ (ComponentInstance)OSAComponent
{
static ComponentInstance theComponent = NULL;
if( !theComponent )
{
theComponent = OpenDefaultComponent( kOSAComponentType,
kAppleScriptSubtype );
}
return theComponent;
}
@implementation NSString (AEDescCreation)
/*
* + stringWithAEDesc:
*/
+ (id)stringWithAEDesc:(const AEDesc *)aDesc
{
NSData * theTextData;
theTextData = [NSData dataWithAEDesc: aDesc];
return ( theTextData == nil ) ? nil : [[[NSString
alloc]initWith
Data:theTextData encoding:NSMacOSRomanStringEncoding]
autorelease];
}
@end
On Tuesday, December 18, 2001, at 07:18 AM, Cynthia Copenhagen wrote:
I am new at Cocoa and am trying to figure out how I can get strings out
of
some of the fields in the Apple System Profiler.
The Apple Script goes something like:
tell application "Apple System Profiler"
get system version as text
end tell
What I am not sure of is how to go through a Cocoa script to call the
AppleScript command.
I have looked everywhere for an example and have read about scripting
in the
documentation.
Could someone please tell me where I can find an example?