Re: Executing short AppleScript command sets
Re: Executing short AppleScript command sets
- Subject: Re: Executing short AppleScript command sets
- From: Nick Zitzmann <email@hidden>
- Date: Thu, 27 Mar 2003 05:37:45 -0800
On Wednesday, March 26, 2003, at 07:34 PM, Jeffrey Mattox wrote:
I know how to call an AppleScript handler in an AppleScript file, but
let's say I have a short snippet of AS code, for example:
tell application "Finder"
name of front window
end tell
Is there a way to run this using Cocoa and get the result, in this
case it's a string, without having it crate a script file, etc.?
Yes, use NSAppleScript: (note - written in Mail, untested, use at your
own risk, etc.)
NSAppleScript *script = [[NSAppleScript alloc] initWithSource:@"tell
application \"Finder\"\nname of front window\nend tell";
NSDictionary *errorDict;
NSAppleEventDescriptor *descriptor = [script
executeAndReturnError:&errorDict];
NSString *result;
if (descriptor != nil)
{
result = [descriptor stringValue];
}
else
{
// handle the error, etc., see the NSAppleScript docs
}
[script release];
Warning: This only works in Mac OS X 10.2 or later.
Nick Zitzmann
AIM/iChat: dragonsdontsleep
Check out my software page:
http://dreamless.home.attbi.com/
"Building the future and keeping the past alive are one and the same
thing." - Metal Gear Solid 2
_______________________________________________
cocoa-dev mailing list | email@hidden
Help/Unsubscribe/Archives:
http://www.lists.apple.com/mailman/listinfo/cocoa-dev
Do not post admin requests to the list. They will be ignored.