< Previous PageNext Page > Hide TOC

Services Properties

Any application that has one or more services to provide must advertise the type of data its services can handle. Services are advertised through the NSServices property of the application’s information property list (Info.plist file).

Note: The information property list (Info.plist) contains key-value pairs that specify the application’s properties that are of interest to the Finder and other applications. Although the Info.plist is a text file that uses XML (Extensible Markup Language) format, you should not modify the XML directly unless you are very familiar with XML syntax. Instead, use Xcode or the Property List Editor application provided with Mac OS X to modify the Info.plist file. You can find more information on property lists in System Overview.

Contents:

Property Definitions
Add-On Services
Sample Property List


Property Definitions

NSServices is a property whose value is an array of dictionaries that specifies the services provided by the application. Keys for each dictionary entry, are as follows:

Add-On Services

You typically define services when you create your application and advertise them in the Info.plist file of the application’s bundle. The services facility also allows you to advertise services outside of the application bundle, enabling you to create “add-on” services after the fact. This is where the NSUserData entry becomes truly useful: You can define a single message in your application that performs actions based on the user data provided, such as running the user data string as a UNIX command or treating it as a special argument in addition to the selected data that gets sent through the pasteboard. To define an add-on service, you create a bundle with a .service extension that contains an Info.plist file, which in turn contains the add-on service specification. The service specification uses the application’s NSMessage and NSPortName values.

Sample Property List

The NSServices property for the Grab application is shown in Figure 1 as it appears in the Property List Editor application.

The NSServices property has three entries, one for each service offered by Grab. The first entry is for the menu item Grab > Selection. The slash notation—Grab/Selection—specifies that Selection should be an item in the Grab submenu. (See Figure 4.)

Note that for each of the three entries, the port name is Grab. As mentioned, the port name is usually the application name.

Each entry has one return type, NSTIFFPboardType. An application could have more than one return type per entry, and the return types don’t necessarily need to be the same for each entry.

The entry for Grab/Timed Screen is the only entry that has a specified timeout value. This optional entry is needed in this case so that the Grab application can wait for the user to set up the screen before taking a screen shot.


Figure 1  The NSServices property for the Grab application

The NSServices property for the Grab application



< Previous PageNext Page > Hide TOC


© 2003, 2002 Apple Computer, Inc. All Rights Reserved. (Last updated: 2002-11-12)


Did this document help you?
Yes: Tell us what works for you.
It’s good, but: Report typos, inaccuracies, and so forth.
It wasn’t helpful: Tell us what would have helped.