Mac:AppleScript

From MozillaWiki
Jump to navigation Jump to search

Right now Gecko is only able to respond to the relevant parts of the standard AppleScript dictionary. We'd like to expand support to allow for more complex interactions. In particular, we want to resolve the following bugs in Firefox:

Current Plan

The bug for improved AppleScript support in Gecko is bug 61356.

Discussed Options

  • Proxy objects: similar to Tom Dyas' work in bug 516502, have an application create their own set of proxy Obj-C classes to respond to Applescript.
    • Pros: native Obj-C solution, less chance of problems interacting with Apple's code
    • Cons: must regularly update proxy objects, may not represent actual state of application. Also, much be maintained on a per-application basis (not within Gecko)
  • Catching requests: override KVC and preformSelector on NSApplication subclass to catch requests from Applescript and forward requests to other classes that register with an Applescript service
    • Pros: can be maintained at the Gecko-level, allows developers with no knowledge of Obj-C to provide functionality to Applescript
    • Cons: could have performance implications (given changes to NSApplication), greater chance of problems interacting with Apple's code

Other Options

  • Override [NSScriptCommand executeCommand]: the stack trace below shows the steps that the system takes to execute an Applescript command:


0 -[NSScriptCommand executeCommand] ()

1 -[NSScriptingAppleEventHandler handleCommandEvent:withReplyEvent:] ()

2 -[NSAppleEventManager dispatchRawAppleEvent:withRawReply:handlerRefCon:] ()

3 _NSAppleEventManagerGenericHandler ()

4 aeDispatchAppleEvent ()

5 dispatchEventAndSendReply ()

6 aeProcessAppleEvent ()

7 AEProcessAppleEvent ()

8 _DPSNextEvent ()

9 -[NSApplication nextEventMatchingMask:untilDate:inMode:dequeue:] ()

10 -[NSApplication run] ()


When it hits executeCommand, the Applescript command is of the form:


Intrinsics.get

Direct Parameter: <NSPropertySpecifier: bookmarks>

Receivers: <NSPropertySpecifier: bookmarks>

Arguments: {}


At this point we could use our own handling to execute the command. The one downside to this is that we loose the automatic support (The Standard suite includes commands such as copy, count, create, delete, exists, and move, as well as common object classes such as application, document, and window).

Scripting Hierarchy

Firefox

  • application
    • windows
      • current tab
      • tabs
        • index
        • name
        • URL
        • source
        • doJavascript?

Plan

The plan is...