David Kramf
David Kramf

Reputation: 207

NSAppleEventDescriptor encoding

The following block is the NSData representation of NSAppleEventDescriptor I get as return of calling NSAppleScript. What is the encoding of the NSData block and how should I convert it to NSString data is

<646c6532 00000000 6c697374 00000174 00000000 00000000 00000018 6c697374 0000000c 00000000 75747874 00000008 0068006f 006d0065 75747874 0000001a 00540065 006d0070 00390033 00370033 00360030 00360031 00367574 78740000 001a0054 0065006d 00700032 00300037 00370030 00390033 00310033 75747874 00000018 00540065 006d0070 00390038 00380039 00340038 00310037 75747874 0000001a 00540065 006d0070 00330033 00350032 00390030 00300031 00397574 78740000 001a0054 0065006d 00700035 00310039 00380039 00380030 00300032 75747874 0000001a 00540065 006d0070 00330030 00300036 00310038 00320031 00387574 78740000 000a0044 00610076 00690064 75747874 00000010 0055006e 00740069 0074006c 00650064 75747874 0000000c 00700067 00690073 00680061 75747874 0000001a 00540065 006d0070 00380038 00390038 00370038 00330034 00357574 78740000 001a0054 0065006d 00700035 00380038 00360038 00320035 00300037>

Many Thanks, David

Upvotes: 0

Views: 931

Answers (1)

foo
foo

Reputation: 3259

Use -[NSAppleEventDescriptor stringValue] - that will coerce the AEDesc to typeUnicodeText if it isn't already one and unpack it as an NSString (or else returns nil if it can't be coerced).

You shouldn't go poking around in -[NSAppleEventDescriptor data] unless you need to decode one of the AE types (e.g. typeLongDateTime) for which NSAppleEventDescriptor doesn't provide convenience pack/unpack methods, but that way madness lies.

If your AppleScript code is part of your application rather than a user-supplied script, consider using AppleScript-ObjC instead of NSAppleScript. Like PyObjC and RubyCocoa, ASOC makes AppleScript script objects appear as regular Cocoa classes and instances to the rest of your program and automatically converts common AS values to their Cocoa equivalents as they cross the bridge, so it's much easier and more powerful to use.

Upvotes: 0

Related Questions