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

ObjC-appscript has an AEMCodecs class that includes code for packing and 
unpacking AppleScript-style records, if you don't mind embedding the Appscript 
framework or extracting the classes you want by hand. (I've received a patch 
from another appscript user to break out AEMCodecs and some other bits for this 
sort of use, but I've been too busy recently to apply it.)


> 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}

Unless the script needs to be user supplied, you could skip the NSAppleScript 
bit altogether. e.g. Running the above script through ASTranslate (from the 
appscript website) gives me the following raw code, which'd clean up nicely:

#import "SFGlue/SFGlue.h"
SFApplication *safari = [SFApplication applicationWithName: @"Safari"];
SFReference *ref = [[[safari documents] at: 1] name];
id result = [ref getItem];

#import "SFGlue/SFGlue.h"
SFApplication *safari = [SFApplication applicationWithName: @"Safari"];
SFReference *ref = [[[safari documents] at: 1] URL];
id result = [ref getItem];

Or there's Apple's own bridge - not as good, but I'm guessing it would work for 
this.

HTH

has
-- 
Control AppleScriptable applications from Python, Ruby and ObjC:
http://appscript.sourceforge.net

_______________________________________________

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