Differences between revisions 1 and 2
Revision 1 as of 2007-02-12 03:30:24
Size: 4482
Comment: next
Revision 2 as of 2007-02-14 01:57:30
Size: 4464
Comment: link fixage
Deletions are marked like this. Additions are marked like this.
Line 3: Line 3:
AppleScript is a scripting language developed by Apple, included as standard in Mac OS (System 7 Pro and later) and Mac OS X. It has two important technical features: !AppleScript is a scripting language developed by Apple, included as standard in Mac OS (System 7 Pro and later) and Mac OS X. It has two important technical features:
Line 5: Line 5:
 * It can communicate with local and remote processes via AppleEvents; commonly known as "application scripting".  * It can communicate with local and remote processes via ../AppleEvents; commonly known as "application scripting".
Line 7: Line 7:
 * It is an ["/OSA"] language component, allowing client applications to load and run scripts via the language agnostic ["OSA"] API. Client applications can use the ["OSA"] API to implement features such as Folder Actions (System Events), Mail rules, iCal alarm scripts, ["OSA"] script editing (Script Editor, Script Debugger), etc.  * It is an ["../OSA"] language component, allowing client applications to load and run scripts via the language agnostic OSA API. Client applications can use the OSA API to implement features such as Folder Actions (System Events), Mail rules, iCal alarm scripts, OSA script editing (Script Editor, Script Debugger), etc.
Line 11: Line 11:
Python provides extensive third-party application scripting support and limited ["/OSA"] language component support. It also supports /AppleEvent handling and can load and use other ["OSA"] language components. Python provides extensive third-party application scripting support and limited OSA language component support. It also supports !AppleEvent handling and can load and use other OSA language components.
Line 15: Line 15:
Python has long supported sending /AppleEvents via the high-level {{{aetools}}} and {{{gensuitemodule}}} modules in its standard library. However, these modules have always had a number of shortcomings and have grown increasingly troublesome in recent Mac OS X releases; in particular, they are completely broken on Intel-based Macs. As a result, these and other AE/OSA-related modules will be removed in a future Python release and their use should be avoided. Python has long supported sending !AppleEvents via the high-level {{{aetools}}} and {{{gensuitemodule}}} modules in its standard library. However, these modules have always had a number of shortcomings and have grown increasingly troublesome in recent Mac OS X releases; in particular, they are completely broken on Intel-based Macs. As a result, these and other AE/OSA-related modules will be removed in a future Python release and their use should be avoided.
Line 17: Line 17:
There is also a low-level extension, {{{Carbon.AE}}}, that can be used to construct and send AppleEvents. Using this API requires detailed knowledge of the Apple Event Manager, however, so is rarely used directly. There is also a low-level extension, {{{Carbon.AE}}}, that can be used to construct and send !AppleEvents. Using this API requires detailed knowledge of the Apple Event Manager, however, so is rarely used directly.
Line 19: Line 19:
A modern replacement to {{{aetools}}} and {{{gensuitemodule}}}, the AppscriptModule, has been available since late 2003. (A second project, aeve, has since been discontinued.) A modern replacement to {{{aetools}}} and {{{gensuitemodule}}}, the ../AppscriptModule, has been available since late 2003. (A second project, aeve, has since been discontinued.)
Line 23: Line 23:
There have been several attempts to develop a Python ["/OSA"] language component, though to date none of them provide a complete replacement for AppleScript. There have been several attempts to develop a Python OSA language component, though to date none of them provide a complete replacement for !AppleScript.
Line 25: Line 25:
 * OSAPython implements much of the ["/OSA"] interface, but is unfinished and is no longer being developed.  * OSAPython implements much of the OSA interface, but is unfinished and is no longer being developed.
Line 27: Line 27:
 * MacPythonOSA is another attempt to implement the full ["/OSA"] interface, but is also unfinished and currently inactive.  * MacPythonOSA is another attempt to implement the full OSA interface, but is also unfinished and currently inactive.
Line 29: Line 29:
 * PythonOSA provides a working implementation of the core ["/OSA"] interface, allowing ["OSA"] scripts written in Python to be loaded, stored, compiled and executed. More advanced ["OSA"] features, such as the ability to send and receive /AppleEvents to and from the host process are not currently available.  * PythonOSA provides a working implementation of the core OSA interface, allowing OSA scripts written in Python to be loaded, stored, compiled and executed. More advanced OSA features, such as the ability to send and receive !AppleEvents to and from the host process are not currently available.
Line 33: Line 33:
The Python standard library has long provided a basic /AppleEvent handing framework, MiniAEFrame, but as with {{{aetools}}} and {{{gensuitemodule}}} this module is unsupported on Intel Macs and will be removed in future, and its use should be avoided. The Python standard library has long provided a basic !AppleEvent handing framework, MiniAEFrame, but as with {{{aetools}}} and {{{gensuitemodule}}} this module is unsupported on Intel Macs and will be removed in future, and its use should be avoided.
Line 35: Line 35:
The low-level {{{Carbon.AE}}} extension can be used to install Apple event handlers, though lacks the ability to install coercion handlers and requires detailed knowledge of the /AppleEventManager to use, so is rarely used directly. The low-level {{{Carbon.AE}}} extension can be used to install Apple event handlers, though lacks the ability to install coercion handlers and requires detailed knowledge of the ../AppleEventManager to use, so is rarely used directly.
Line 37: Line 37:
There are two modern, high-level options for implementing /AppleEvent handling in Python-based applications: There are two modern, high-level options for implementing !AppleEvent handling in Python-based applications:
Line 39: Line 39:
 * aemreceive (bundled with the AppscriptModule) can be used to install /AppleEvent handlers although it provides no assistance for resolving object references so is best suited for use in applications that don't implement an AppleEventObjectModel.  * aemreceive (bundled with the !AppscriptModule) can be used to install !AppleEvent handlers although it provides no assistance for resolving object references so is best suited for use in applications that don't implement an ../AppleEventObjectModel.
Line 41: Line 41:
 * PyObjC-based applications can leverage the /AppKit framework's built-in Cocoa Scripting support to implement a full AppleEventObjectModel.  * PyObjC-based applications can leverage the /AppKit framework's built-in Cocoa Scripting support to implement a full !AppleEventObjectModel.
Line 47: Line 47:
 * The {{{CarbonX.OSA}}} extension (bundled with the AppscriptModule) provides a low-level wrapper around the OSA API. (There is also a {{{Carbon.OSA}}} extension included in Python 2.4 and later, but it provides only a partial implementation and contains several bugs so is best avoided.) A high-level wrapper for {{{CarbonX.OSA}}} is under development.  * The {{{CarbonX.OSA}}} extension (bundled with the !AppscriptModule) provides a low-level wrapper around the OSA API. (There is also a {{{Carbon.OSA}}} extension included in Python 2.4 and later, but it provides only a partial implementation and contains several bugs so is best avoided.) A high-level wrapper for {{{CarbonX.OSA}}} is under development.
Line 53: Line 53:
 * ["/aeve"]
 * /AppscriptModule
 * /AppleEvents
 * /AppleScriptNotes
 * /FourCharacterCode
 * ["/OSA"]
 * ["../aeve"]
 * ../AppscriptModule
 * ../AppleEvents
 * ../AppleScriptNotes
 * ../FourCharacterCode
 * ["../OSA"]

What is AppleScript?

AppleScript is a scripting language developed by Apple, included as standard in Mac OS (System 7 Pro and later) and Mac OS X. It has two important technical features:

  • It can communicate with local and remote processes via ../AppleEvents; commonly known as "application scripting".

  • It is an ["../OSA"] language component, allowing client applications to load and run scripts via the language agnostic OSA API. Client applications can use the OSA API to implement features such as Folder Actions (System Events), Mail rules, iCal alarm scripts, OSA script editing (Script Editor, Script Debugger), etc.

Equivalent Python Features

Python provides extensive third-party application scripting support and limited OSA language component support. It also supports AppleEvent handling and can load and use other OSA language components.

Application scripting

Python has long supported sending AppleEvents via the high-level aetools and gensuitemodule modules in its standard library. However, these modules have always had a number of shortcomings and have grown increasingly troublesome in recent Mac OS X releases; in particular, they are completely broken on Intel-based Macs. As a result, these and other AE/OSA-related modules will be removed in a future Python release and their use should be avoided.

There is also a low-level extension, Carbon.AE, that can be used to construct and send AppleEvents. Using this API requires detailed knowledge of the Apple Event Manager, however, so is rarely used directly.

A modern replacement to aetools and gensuitemodule, the ../AppscriptModule, has been available since late 2003. (A second project, aeve, has since been discontinued.)

Python OSA language components

There have been several attempts to develop a Python OSA language component, though to date none of them provide a complete replacement for AppleScript.

  • OSAPython implements much of the OSA interface, but is unfinished and is no longer being developed.
  • MacPythonOSA is another attempt to implement the full OSA interface, but is also unfinished and currently inactive.
  • PythonOSA provides a working implementation of the core OSA interface, allowing OSA scripts written in Python to be loaded, stored, compiled and executed. More advanced OSA features, such as the ability to send and receive AppleEvents to and from the host process are not currently available.

Apple event handling

The Python standard library has long provided a basic AppleEvent handing framework, MiniAEFrame, but as with aetools and gensuitemodule this module is unsupported on Intel Macs and will be removed in future, and its use should be avoided.

The low-level Carbon.AE extension can be used to install Apple event handlers, though lacks the ability to install coercion handlers and requires detailed knowledge of the ../AppleEventManager to use, so is rarely used directly.

There are two modern, high-level options for implementing AppleEvent handling in Python-based applications:

  • aemreceive (bundled with the AppscriptModule) can be used to install AppleEvent handlers although it provides no assistance for resolving object references so is best suited for use in applications that don't implement an ../AppleEventObjectModel.

  • PyObjC-based applications can leverage the /AppKit framework's built-in Cocoa Scripting support to implement a full AppleEventObjectModel.

OSA API access

There are currently two ways to access the OSA API in Python:

  • The CarbonX.OSA extension (bundled with the AppscriptModule) provides a low-level wrapper around the OSA API. (There is also a Carbon.OSA extension included in Python 2.4 and later, but it provides only a partial implementation and contains several bugs so is best avoided.) A high-level wrapper for CarbonX.OSA is under development.

  • PyObjC includes a wrapper for the (currently undocumented) OSAKit API on OS 10.4 and later.

See also

MacPython/AppleScript (last edited 2011-03-08 10:14:53 by 82)

Unable to edit the page? See the FrontPage for instructions.