• Open Menu Close Menu
  • Apple
  • Shopping Bag
  • Apple
  • Mac
  • iPad
  • iPhone
  • Watch
  • TV
  • Music
  • Support
  • Search apple.com
  • Shopping Bag
 

Lists

Open Menu Close Menu
  • Terms and Conditions
  • Lists hosted on this site
  • Email the Postmaster
  • Tips for posting to public mailing lists
building an AppleScript editor app
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

building an AppleScript editor app


  • Subject: building an AppleScript editor app
  • From: sqwarqDev <email@hidden>
  • Date: Sun, 07 Dec 2014 16:46:33 +0700


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


 _______________________________________________
Do not post admin requests to the list. They will be ignored.
AppleScript-Users mailing list      (email@hidden)
Help/Unsubscribe/Update your Subscription:
Archives: http://lists.apple.com/archives/applescript-users

This email sent to email@hidden

  • Prev by Date: [FYI] Script Debugger
  • Next by Date: Re: building an AppleScript editor app
  • Previous by thread: [FYI] Script Debugger
  • Next by thread: Re: building an AppleScript editor app
  • Index(es):
    • Date
    • Thread