Mac:AppleScript: Difference between revisions

Line 8: Line 8:
= Current Plan  =
= Current Plan  =


The bug for improved AppleScript support in Gecko is {{bug|61356}}.  
The bug for improved AppleScript support in Gecko is {{bug|61356}}.
 
The ideal solution is to allow Gecko applications to dynamically register for Applescript commands which are then forwarded to them, without the caller needing to write their own Objective-C.
 
e.g. if Firefox Sync would like to have an Applescript command "tell application "Firefox" to sync", it could register with the Applescript service to forward all "sync" Applescript requests to their Javascript code.


'''Discussed Options'''
'''Discussed Options'''
Line 15: Line 19:
**Pros: native Obj-C solution, less chance of problems interacting with Apple's code
**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)
**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
*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
**Pros: can be maintained at the Gecko-level, allows developers with no knowledge of Obj-C to provide functionality to Applescript
Line 21: Line 26:
'''Other Options'''
'''Other Options'''


*Override [NSScriptCommand executeCommand]: the stack trace below shows the steps that the system takes to execute an Applescript command:
*Override [NSScriptCommand executeCommand] and do our own parsing and handling of Applescript commands.


'''Scripting Hierarchy'''


0  -[NSScriptCommand executeCommand] ()
Gecko
 
*application
1  -[NSScriptingAppleEventHandler handleCommandEvent:withReplyEvent:] ()
**windows
 
***current tab?
2  -[NSAppleEventManager dispatchRawAppleEvent:withRawReply:handlerRefCon:] ()
***tabs?
 
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: {}
 
(from the applescript command "get bookmarks")
 
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
Firefox
31

edits