Hi Jerry-

You're going to want to look at NSAppleEventDescriptor's numberOfItems, 
keywordForDescriptorAtIndex: and descriptorAtIndex: methods, and play around 
with them a little.  One thing to keep in mind is that the lists are 1-based, 
so start looking at index 1 :-)  It's been quite some time since I played with 
this, so consider the below as suggestions rather than known truth...

For the descriptor you logged, there should be one item, 
keywordForDescriptorAtIndex:1 should return 'usrf', and descriptorAtIndex:1 
will return a descriptor that you can further interrogate (lets call it "info").

NSAppleEventDescriptor also has methods to return values for descriptors.  To 
get at the data you are looking for you'll need to use the stringValue method 
to fish out the data.  Consider the following (email typed, untested) snippet 
to access the data

NSMutableDictionary *tempDict = [NSMutableDictionary dictionary];
NSUInteger i, count = 2;
for(i = 1; i <= count; i++){
        NSString *newKey = [[info descriptorAtIndex:(2*i-1)] stringValue];
        NSString *newValue = [info descriptorAtIndex:(2*i)] stringValue];
        [tempDict addObject:newValue for Key:newKey];
}

You should now have a dictionary where aNam => Apple and aUrl => 
http://www.apple.com

Hope this helps!

John




On Feb 20, 2010, at 10:15 PM, Jerry Krinock wrote:

> I create an NSAppleScript to read the current window name and URL from Safari 
> and return it as a record [1].  When I execute it, I get a nice-looking 
> NSAppleEventDescriptor with the following -description (line breaks added for 
> readability):
> 
> <NSAppleEventDescriptor: {
>           'usrf':
>            [
>               'utxt'("aNam"),
>               'utxt'("Apple"),
>               'utxt'("aUrl"),
>               'utxt'("http://www.apple.com";)
>            ] }>
> 
> As you can see, the desired keys and values are all in there.  How can I get 
> them out?  (Spent an hour reading documentation to no avail.)
> 
> Thanks,
> 
> Jerry Krinock
> 
> [1] 
> tell application "Safari"
>    set aName to name of front document
>    set aUrl to URL of front document
> end tell
> set aRecord to {aNam:aName, aUrl:aUrl}
> 
> _______________________________________________
> 
> Cocoa-dev mailing list (Cocoa-dev@lists.apple.com)
> 
> 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:
> http://lists.apple.com/mailman/options/cocoa-dev/john%40positivespinmedia.com
> 
> This email sent to j...@positivespinmedia.com

_______________________________________________

Cocoa-dev mailing list (Cocoa-dev@lists.apple.com)

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:
http://lists.apple.com/mailman/options/cocoa-dev/archive%40mail-archive.com

This email sent to arch...@mail-archive.com

Reply via email to