This chapter describes the terminology in the Plugin suite.
Starting in AppleScript Studio version 1.3, first distributed with Mac OS X version 10.3, Xcode provides a new template for creating an AppleScript plug-in for Xcode. That is, you can use AppleScript Studio to create a plug-in that adds features to Xcode itself. The Plugin suite provides terminology to use with plug-ins of this type.
The classes and events in the Plugin suite are described in the following sections:
For enumerated constants, see “Enumerations.”
The Plugin suite contains the following class:
Represents an application plugin.
You build plug-ins using the Xcode project template “AppleScript Xcode Plugin.” Once you have built a plugin, you place it in one of the following locations so that it will be loaded the next time Xcode is launched:
/Library/Application Support/Apple/Developer
Tools/Plug-Ins
~/Library/Application Support/Apple/Developer
Tools/Plug-Ins
/Network/Library/Application Support/Apple/Developer
Tools/Plug-Ins
A plugin
object has read only access to the properties of its parent class.
The most common reason for creating an AppleScript Xcode plug-in is to add new functionality to Xcode by taking advantage of its scriptability. This can be useful because Xcode supports a robust scripting terminology, and it is possible to provide plug-in features that are not currently available through the Xcode user interface.
For an example that demonstrates how to add a menu and menu item to Xcode, see the examples section for the plugin loaded
event handler.
The plugin
class was added in AppleScript Studio version 1.3.
Objects in the Plugin Suite support the following events (an event is an action, typically generated through interaction with an application’s user interface, that causes a handler for the appropriate object to be executed).
Called when the plug-in to which the handler is attached is loaded.
You typically use this handler to create any interface items you are adding to Xcode (such as menus or menu items) and to create any scripts to handle actions involving those interface items.
plugin loaded |
reference | required |
a reference to the object whose plugin
loaded
handler is called
This example describes how to create a plug-in application and use it to add a menu and a simple menu item to Xcode.
To create an AppleScript plug-in project in Xcode, you follow these steps:
Choose File > New Project
In the New Project Assistant window, scroll down to the section for Standard Apple Plug-ins.
Select AppleScript Xcode Plugin
To hook up the plugin handler for the application, you follow these steps:
Select the project in the Groups & Files list in Xcode. The project’s files should then be visible in the detail view.
Double-click the nib file to open it in Interface Builder.
In Interface Builder, select “File’s Owner” in the nib window.
Open an Info window (type Command-Shift-I or choose Tools > Show Info).
Display the AppleScript pane (type Command-7, or use the pop-up menu).
Open the Plugin group and select the plugin
loaded
handler.
Select the script file below, then click the Edit Script button. That will take you back to Xcode, with an open script file containing an empty plugin loaded
handler.
Listing 10-1 provides an example of code you might put in your plugin loaded
handler. This example adds a “Plug-ins” menu to Xcode and adds a “Display Dialog” menu item to the menu. It also defines a script and attaches the script to the menu item. The script displays a dialog.
Remember that after you build your plug-in, you place it in the one of the locations described in plugin
, so that it will be loaded the next time Xcode is launched.
Listing 10-1 A sample plugin loaded handler
on plugin loaded theBundle |
-- Make a new script |
script pluginScript |
property someVariable : "Display Dialog" |
on choose menu item theObject |
display dialog someVariable |
end choose menu item |
end script |
-- Make a new plugin menu |
set pluginMenu to make new menu at end of menus of main menu with properties {title:"Plug-ins", name:"plugins"} |
-- Make a new Display Dialog menu item in the plugin menu |
set pluginItem to make new menu item at beginning of menu items of pluginMenu with properties {title:"Display Dialog", name:"display dialog"} |
-- Set the script of the new menu item |
set script of pluginItem to pluginScript |
end plugin loaded |
The plugin loaded
event handler was added in AppleScript Studio version 1.3.
© 2007 Apple Inc. All Rights Reserved. (Last updated: 2007-10-31)