AppleScript Execution Context Overview
Introduction
The built-in Bellhop AppleScript Execution Context plug-in executes services that are implemented in the AppleScript language. The plug-in provides a set of subroutines and global variables that are available to your scripts. Unlike the Ruby extensions, however, the AppleScript support only provides routines to manipulate the contents of a given pastebaord; interaction with the user and the Finder relies on the builtin facilities of AppleScript.
In order to support AppleScript, the plug-in automatically loads some "glue" code into your service scripts at runtime. This "pasteboard glue" contains the various subroutines and global variables that you will use in your services to interact with pasteboards, and are explained in more detail in the Reference part of this document.
Basic Syntax
AppleScript services can be structured quite freely; the only requirement is that the script contain a run handler that takes a single argument. The name of this handler should be runService() and it should take a single string argument that specifies the name of the pasteboard instance responsible for a service transaction. The listing below shows the basic structure of an AppleScript service.
on runService(aPasteboard) (* Put your custom AppleScript code here in the runService() handler. It will automatically be invoked when a user selects the service from the menu. *) end runService
The aPasteboard argument will be a string that specifies the unique pasteboard name for the service transaction, and is automatically passed to the handler by Bellhop.
Other than the required runService() handler, you are free structure your scripts as you wish, and you can make use of any AppleScript features and additions that are available to you.
For a more detailed AppleScript example, see the Example section of this document.
AppleScript Pasteboard "Glue"
As metioned above, the Bellhop AppleScript plug-in implements a set of subroutines and constants (known as the Pasteboard Glue) that allow your AppleScript services to interact with the Mac OS X Services System. The subroutines all deal with getting and setting pasteboard contents, as well as querying and declaring the types of pasteboard contents. All of the known pasteboard types are provided as symbolic constants to your scripts, and match the names as defined in the Cocoa frameworks (e.g. NSStringPboardType is used to declare string data on a pasteboard). Additionally, the general pasteboard is also identified by its name, NSGeneralPboard, which is available in your own AppleScript services (so that you can also target the clipboard, for example).
For a complete description of the various subroutines, see the Reference section of this document.