On Sat, 21 Mar 2009 12:38:11 -0500, Steve Cronin <steve_cro...@mac.com>
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 = m...@tidbits.com, <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 (Cocoa-dev@lists.apple.com)

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:
http://lists.apple.com/mailman/options/cocoa-dev/archive%40mail-archive.com

This email sent to arch...@mail-archive.com

Reply via email to