• 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: Fetching result from NSAppleScript
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: Fetching result from NSAppleScript


  • Subject: Re: Fetching result from NSAppleScript
  • From: Nirnimesh <email@hidden>
  • Date: Fri, 20 Jul 2007 03:03:14 +0530

On 7/20/07, has <email@hidden> wrote:

Nirnimesh wrote:

> I want to run an applescript and fetch its results in my cocoa app.
> The applescript is: tell application \"Finder\" to get every window
>
> [...]
>     NSAppleEventDescriptor* des = [script
> executeAndReturnError:&errorDict];
>     NSData* rawdata = [des data];
>     NSString* out = [NSString stringWithCharacters:[rawdata bytes]
> length:
> [rawdata length]/sizeof(unichar)];
> [...]
> The above doesn't work. I get:
> output `\262\200\240\220
>
> How can I fetch the output?

What output were you hoping to get? The script is returning a list of
object specifiers, e.g.:

#import <Cocoa/Cocoa.h>

int main(int argc, char *argv[]) {
     NSAutoreleasePool* pool = [[NSAutoreleasePool alloc] init];
     NSAppleScript* script = [[NSAppleScript alloc] initWithSource:
             @"tell application \"Finder\" to get every window"];
     NSAppleEventDescriptor* des = [script executeAndReturnError:NULL];
     NSLog(@"%@", des);
     [pool release];
     return 0;
}

Result:

<NSAppleEventDescriptor: [
     'obj '{ 'form':'ID  ', 'want':'brow', 'seld':491,
'from':''null''() },
     'obj '{ 'form':'ID  ', 'want':'brow', 'seld':448,
'from':''null''() },
     'obj '{ 'form':'ID  ', 'want':'brow', 'seld':490,
'from':''null''() }
]

You need to use the methods provided by NSAppleEventDescriptor to
manipulate that data further. If you want more specific advice, you
need to say a bit more about what you're trying to achieve.


Well, I was hoping to get output similar to what osascript would return. I
now realize that as long as the script returns text, I get what I want, but
not for other datatypes (as list, in the example above). Is there really a
way I could just convert all of these datatypes to text, just like osascript
does?

(I cannot directly use osascript because I want to use unicode chars and the
shell messes it up)

Thanks Has


../NiR -- Gravitation is not responsible for people falling in love. -- Albert Einstein. _______________________________________________

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: Fetching result from NSAppleScript
      • From: has <email@hidden>
References: 
 >Re: Fetching result from NSAppleScript (From: has <email@hidden>)

  • Prev by Date: Re: Newbie Question: Why would my App freeze when I select a row in an NSTableView?
  • Next by Date: Re: Fetching result from NSAppleScript
  • Previous by thread: Re: Fetching result from NSAppleScript
  • Next by thread: Re: Fetching result from NSAppleScript
  • Index(es):
    • Date
    • Thread