• 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: Steve Cronin <email@hidden>
  • Date: Sun, 22 Mar 2009 12:12:45 -0500

Matt;

I really take offense at your tone. I was not lying.
I merely clipped out my personal details in order not to provide them to the world.
The 'theScript' IS a string - constructed in ObjC differently than you show but a string nonetheless.


Turns out the error was that an SDEF file had been renamed.

As Samuel Jackson said in "Black Snake Moan" --  "Collar that dog!",
Steve

On Mar 22, 2009, at 12:05 PM, Matt Neuburg wrote:

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


References: 
 >Re: NSAppleScript - what is going on here? (From: Matt Neuburg <email@hidden>)

  • Prev by Date: Re: NSAppleScript - what is going on here?
  • Next by Date: Re: NSAppleScript - what is going on here?
  • Previous by thread: Re: NSAppleScript - what is going on here?
  • Next by thread: MacRoman -> UTF8
  • Index(es):
    • Date
    • Thread