• Open Menu Close Menu
  • Apple
  • Shopping Bag
  • Apple
  • Mac
  • iPad
  • iPhone
  • Watch
  • TV
  • Music
  • Support
  • Search apple.com
  • Shopping Bag

Lists

Open Menu Close Menu
  • Terms and Conditions
  • Lists hosted on this site
  • Email the Postmaster
  • Tips for posting to public mailing lists
Re: Executing short AppleScript command sets
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

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.
  • Follow-Ups:
    • Re: Executing short AppleScript command sets
      • From: Jeffrey Mattox <email@hidden>
References: 
 >Executing short AppleScript command sets (From: Jeffrey Mattox <email@hidden>)

  • Prev by Date: PackageMaker meta package error 999
  • Next by Date: NSTableView Bug (or I cocked up)
  • Previous by thread: Executing short AppleScript command sets
  • Next by thread: Re: Executing short AppleScript command sets
  • Index(es):
    • Date
    • Thread