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.

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’s NSServices property. The property uses the application’s NSMessage and NSPortName values.

Sample Property List

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

Figure 1  The NSServices property for Safari
The NSServices property for Safari

The NSServices property has one entry that represents the only service offered by Safari: “Search with Google.” Note that, for this entry, the port name is Safari. As mentioned, the port name is usually the application name.

The entry has one return type, NSStringPboardType. An application can have more than one return type per entry, and the return types don’t necessarily need to be the same for each entry. Both Uniform Type Identifiers and pasteboard types are valid here. (For more information on Uniform Type Identifiers, see Uniform Type Identifiers Overview.)

The entry has a key equivalent of L, which means that Command-L can be used to invoke the service.