• 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: NSAppleScript - what is going on here?
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: NSAppleScript - what is going on here?


  • Subject: Re: NSAppleScript - what is going on here?
  • From: Matt Neuburg <email@hidden>
  • Date: Sun, 22 Mar 2009 10:05:21 -0700
  • Thread-topic: NSAppleScript - what is going on here?

On Sat, 21 Mar 2009 12:38:11 -0500, Steve Cronin <email@hidden>
said:
>Folks;
>
>I'm trying to get a string value back from a simple AppleScript in
>Cocoa:
>
>NSDictionary *errorDict= nil;
>NSAppleScript *appleScriptObject = [[NSAppleScript alloc]
>initWithSource:theScript];
>NSAppleEventDescriptor *eventDescriptor = [appleScriptObject
>executeAndReturnError: &errorDict];
>[appleScriptObject release];
>if (([eventDescriptor descriptorType]) && (errorDict==nil)) {
> return [self stringFromAppleEventDescriptor:eventDescriptor];  //my
>own method that checks descriptorType and returns stringValue
>} else {
> NSLog(@"%@",[errorDict objectForKey:@"NSAppleScriptErrorMessage"]);
> return nil;
>}
>
>The 'theScript' is a valid script that executes flawlessly in 'Script
>Editor':
>tell application "Finder"
> try
>  comment of file ("/Users/steve/...." as POSIX file)
> on error
>  return "Error"
> end try
>end tell
>
>The problem is that the above errors out @ [appleScriptObject
>executeAndReturnError: &errorDict];
>The stack is shown below.

That's hard to answer because you're so obviously lying. You are not
reporting what you're really doing. What is theScript really? A string? Show
us the string. And clearly you are not really saying /Users/steve/...., so
show us what you *are* saying.

Let me show you how to answer. Here is a *complete* valid chunk of *real*
Objective-C code:

    NSString* theScript = @"tell application \"Finder\"\n"
    @"try\n"
    @"set pp to \"/Users/mattneub/Desktop/BrahmsHandel2.mus\"\n"
    @"comment of file (pp as POSIX file)\n"
    @"on error\n"
    @"return \"Error\"\n"
    @"end try\n"
    @"end tell\n";
    NSDictionary *errorDict= nil;
    NSAppleScript *appleScriptObject = [[NSAppleScript alloc]
initWithSource:theScript];
    NSAppleEventDescriptor *eventDescriptor = [appleScriptObject
executeAndReturnError: &errorDict];
    [appleScriptObject release];
    if (([eventDescriptor descriptorType]) && (errorDict==nil)) {
        NSLog(@"%@", [eventDescriptor stringValue]);
    } else {
        NSLog(@"%@",[errorDict objectForKey:@"NSAppleScriptErrorMessage"]);
    }

I actually ran that code and it actually works (the finder comment from the
specified file appears in the log). Okay, now it's your turn. :) m.

--
matt neuburg, phd = email@hidden, <http://www.tidbits.com/matt/>
A fool + a tool + an autorelease pool = cool!
AppleScript: the Definitive Guide - Second Edition!
http://www.tidbits.com/matt/default.html#applescriptthings



_______________________________________________

Cocoa-dev mailing list (email@hidden)

Please do not post admin requests or moderator comments to the list.
Contact the moderators at cocoa-dev-admins(at)lists.apple.com

Help/Unsubscribe/Update your Subscription:

This email sent to email@hidden

  • Follow-Ups:
    • Re: NSAppleScript - what is going on here?
      • From: Steve Cronin <email@hidden>
  • Prev by Date: Programmatically Change Icon
  • Next by Date: Re: NSAppleScript - what is going on here?
  • Previous by thread: Re: NSAppleScript - what is going on here?
  • Next by thread: Re: NSAppleScript - what is going on here?
  • Index(es):
    • Date
    • Thread