• 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: Jeffrey Mattox <email@hidden>
  • Date: Thu, 27 Mar 2003 13:41:55 -0600

Thank you to all who replied on and off list to this. It appears this is a popular task.

I've done some experiments, and I find that "executeAndReturnError:" takes considerable time to run. There must be compile steps in there. Is there a way to turn a script into, say, Apple events, and then execute those faster? Perhaps by running an AppleScript script somewhere and capturing the compiled commands, whatever?

If so, please use my example (tell application "Finder to do something simple).

Jeff


At 5:37 AM -0800 3/27/03, Nick Zitzmann wrote:
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.
_______________________________________________
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.

References: 
 >Re: Executing short AppleScript command sets (From: Nick Zitzmann <email@hidden>)

  • Prev by Date: Re: Japanese name for FileMaker
  • Next by Date: WindowControllers and threads
  • Previous by thread: Re: Executing short AppleScript command sets
  • Next by thread: Re: Executing short AppleScript command sets
  • Index(es):
    • Date
    • Thread