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



That descriptor is corrupt -- whoever made it is putting UTF-16 data in, but claiming that it's typeText, which is some other encoding (to you, probably Mac OS Roman).  -stringValue would be doing the right thing if not for that.

Incidentally, getting a particular value out of an AERecord (or an AppleEvent, such as you have) using -descriptorAtIndex: is not reliable, since there may be other items, and they're not guaranteed to be in any particular order.  Use "descriptorForKeyword:'----'" instead.


--Chris Nebel
AppleScript Engineering

On Nov 2, 2007, at 8:09 AM, Ivan C Myrvold wrote:

Looks like the string is not empty at all. The length of the string is correct, 188, but when I look at the chars, they alternate between 0 and the chars ASCII code:

NSString* returnObject = [[[replyDescriptor descriptorAtIndex:1] descriptorAtIndex:1] stringValue];

(gdb) p (char)[returnObject characterAtIndex:0]
$1 = 0 '\000'
Current language:  auto; currently objective-c
(gdb) p (char)[returnObject characterAtIndex:1]
$2 = 68 'D'
(gdb) p (char)[returnObject characterAtIndex:2]
$3 = 0 '\000'
(gdb) p (char)[returnObject characterAtIndex:3]
$4 = 101 'e'
(gdb) p (char)[returnObject characterAtIndex:4]
$5 = 0 '\000'
(gdb) p (char)[returnObject characterAtIndex:5]
$6 = 116 't'
(gdb)

Den 2. nov.. 2007 kl. 12:35 skrev Ivan C Myrvold:

I am unable to extract the text from an NSAppleEventDescriptor into an NSString.

Here is the AppleEvent:

{ 1 } 'aevt':  aevt/ansr (i386){
          return id: 669057032 (0x27e10008)
     transaction id: 0 (0x0)
  interaction level: 112 (0x70)
     reply required: 0 (0x0)
             remote: 0 (0x0)
      for recording: 0 (0x0)
         reply port: 0 (0x0)
  target:
    { 1 } 'psn ':  8 bytes {
      { 0x0, 0xed0ed } (InCopy)
    }
  fEventSourcePSN: { 0x0,0xed0ed } (InCopy)
  optional attributes:
    < empty record >
  event data:
    { 1 } 'aevt':  - 1 items {
      key '----' - 
        { 1 } 'list':  - 1 elements {
          { 1 } 'TEXT':  188 bytes {
            "

Here are the things I have tried:

(gdb) po [replyDescriptor descriptorAtIndex:1]
<NSAppleEventDescriptor: [ "\D\e\t\t\e\ \e\r\ \e\n\ \t\e\k\s\t\.\r\S\k\r\i\v\e\r\ \l\i\n\j\e\ \2\.\ \N\y\ \s\e\t\n\i\n\g\ \l\i\n\j\e\ \2\.\r\D\e\t\t\e\ \e\r\ \l\i\n\j\e\ \3\.\r\L\i\n\j\e\ \4\ \e\r\ \s\l\u\t\t\e\n\.\r" ]>
(gdb) po [[replyDescriptor descriptorAtIndex:1] descriptorAtIndex:1]
<NSAppleEventDescriptor: "\D\e\t\t\e\ \e\r\ \e\n\ \t\e\k\s\t\.\r\S\k\r\i\v\e\r\ \l\i\n\j\e\ \2\.\ \N\y\ \s\e\t\n\i\n\g\ \l\i\n\j\e\ \2\.\r\D\e\t\t\e\ \e\r\ \l\i\n\j\e\ \3\.\r\L\i\n\j\e\ \4\ \e\r\ \s\l\u\t\t\e\n\.\r">
(gdb) po [[[replyDescriptor descriptorAtIndex:1] descriptorAtIndex:1] stringValue]
<object returned empty description>
(gdb) 


I only get an empty string. What should I do in this case?

Ivan
_______________________________________________
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

_______________________________________________
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

 _______________________________________________
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>)



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.