Mailing Lists: Apple Mailing Lists

Image of Mac OS face in stamp
 
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: Extract text out of NSAppleEventDescriptor




Den 3. nov.. 2007 kl. 05:29 skrev Philip Aker:

On 2007-02-11, at 10:29, Ivan C Myrvold wrote:

You're getting big endian unicode text. Coerce it to typeUTF8Text and things might be better for a console printout.

I am not sure how to do that, but isn't there an easy way to make this a proper NSString?
The text is showing just fine when shown in an NSView, by the way, when using binding of the NSString variable.

Folks agree that you're not getting a valid input. If you have no options to change the input, then the easiest thing is to get the raw bytes and take a chance on something similar to CFStringCreateFromExternalRepresentation() or CFStringCreateWithFormat() since we've seen the bytes are big endian. CFStringCreateWithFormat() presumes a lot in terms of encoding while other raw byte constructors make you guess.

So (c99):

This is unknown territory for me. I tried to obtain the AEDesc desc, to plug it into your routine below:

OSStatus err = AESendMessage(theAppleEventPtr, &reply, kAEWaitReply, kAEDefaultTimeout);
NSAppleEventDescriptor *replyDescriptor = [[[NSAppleEventDescriptor alloc] initWithAEDescNoCopy:&reply] autorelease];

AEDesc desc = [replyDescriptor aeDesc];

Xcode reports error: invalid initializer

Ivan

SInt32 size = AEGetDescDataSize( &desc );
UInt8 buffer[size + 2];
bzero( &buffer, size + 2 );
err = AEGetDescData( &desc, buffer, size );

NSString *nstr = (NSString *)CFStringCreateWithFormat( kCFAllocatorDefault, NULL, CFSTR( "%S" ), buffer );

HTH,

Philip Aker
echo email@hidden@nl | tr a-z@. p-za-o.@



 _______________________________________________
Do not post admin requests to the list. They will be ignored.
Applescript-implementors mailing list      (email@hidden)
Help/Unsubscribe/Update your Subscription:
http://lists.apple.com/mailman/options/applescript-implementors/email@hidden

This email sent to email@hidden

References: 
 >Extract text out of NSAppleEventDescriptor (From: Ivan C Myrvold <email@hidden>)
 >Re: Extract text out of NSAppleEventDescriptor (From: Ivan C Myrvold <email@hidden>)
 >Re: Extract text out of NSAppleEventDescriptor (From: Philip Aker <email@hidden>)
 >Re: Extract text out of NSAppleEventDescriptor (From: Ivan C Myrvold <email@hidden>)
 >Re: Extract text out of NSAppleEventDescriptor (From: Philip Aker <email@hidden>)



Visit the Apple Store online or at retail locations.
1-800-MY-APPLE

Contact Apple | Terms of Use | Privacy Policy

Copyright © 2007 Apple Inc. All rights reserved.