Re: Extract keys, values from 'usrf' Record Type NSAppleEventDescriptor?
Re: Extract keys, values from 'usrf' Record Type NSAppleEventDescriptor?
- Subject: Re: Extract keys, values from 'usrf' Record Type NSAppleEventDescriptor?
- From: John Pannell <email@hidden>
- Date: Sun, 21 Feb 2010 07:32:11 -0700
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 (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
_______________________________________________
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