Apologies for cross-posting, but I suspect there could be experts on both sides 
of the divide that may be able to help me. 

As the title suggests, I'm building an AppleScript editor (Objective-C, not 
Swift). I've got reasonably far replicating the abilities of the in-built 
Script editor and have even added a few bells and whistles. However, I'm stuck, 
conceptually, on one particular hump.

When a script in my editor returns a record that contains the four-letter codes 
defined in the target application's dictionary, what is the best way to 
translate the code back into human readable form for display in the results 
window?

For example, a simple script like this run in my editor:

> tell application "System Events"
>       activate
>       get properties
> end tell


will produce something like this:

> AEDescriptor is:
> <NSAppleEventDescriptor: 'capp'{ 'desk':'obj '{ 'form':'name', 'want':'cfol', 
> 'seld':'utxt'("Fusion:Users:sphil:Desktop:"), ..., ....

To see the output I want, just run the AppleScript code in OS X's built-in 
Script Editor and look at the Results pane. 

I can get seld's 'utxt' easily enough with the stringValue property, but I'm 
assuming the rest require parsing the codes from the target app's dictionary 
(unless someone know's a better way). 

I haven't yet got round to building my XML parser for my Dictionary viewer 
(that's next up), so I don't know if there are some methods that might help me 
in NSXML (a brief look over the class didn't suggest anything useful), but I'm 
imagining that I'm going to have to do something like this:

i. load the applications dictionary into my code 
        --> (I'm assuming I do this with an NSTask calling sdef...any other 
suggestions?)

ii. parse the AEDescriptor result  for the four-letter codes 
        --> (currently, my thinking here is to turn the whole result into an 
NSString and use an NSScanner)

iii. see if each has a match in the target application's dictionary
        --> (I'm thinking some devil's brew of a concoction with regex, 
NSString methods and C functions to scan and match patterns, substrings and 
chars)

iv. if a match is found, format a result string from the match.
        --> (haven't figured out how I'll do this yet; it'll obviously depend 
very much on what monstroisty I come up with in iii.)


While all that's a lot of code, errors and edge-cases to debug, it's not an 
insurmountable challenge (he says intrepidly, looking up from the bottom of the 
mountain with no idea of the obstacles hiding on the trail...), but before I 
set off on such a mammoth trek, I'm wondering if there's an easier/better way 
to do all this, or (thinking that Christmas is coming...) even an API that'll 
do large part of it for me....

Any thoughts would be massively appreciated!



Best


Phil


_______________________________________________

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

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

Reply via email to