Using contextual menu and toolbar item keys
Learn about adding contextual menu items and toolbar items to a Safari app extension with information property list keys.
Overview
Contextual menu items and toolbar items give you ways to add more menu options and entry points to your Safari app extension. You define and adjust these items using information property list keys.
Add context menu items
The SFSafariContextMenu key lets your app extension add items to the context menu that appears in webpages. See Context menus for design guidelines.
[Image]
The key’s value must be an array, and must contain one dictionary with two subkeys for each menu item.
Subkey | Type | Description |
|---|---|---|
| String | Required. A string that specifies the text to display for the context menu item. |
| String | Required. A string that the context menu item sends when it activates. It contains the name of the command you want to send to your app extension when the user selects your item. |
For example, if you add two contextual menu items, your Info.plist file might look like the following:
<key>SFSafariContextMenu</key>
<array>
<dict>
<key>Text</key>
<string>Search for selected text in MyApplication.</string>
<key>Command</key>
<string>Search</string>
</dict>
<dict>
<key>Text</key>
<string>Add an entry for selected text in MyApplication.</string>
<key>Command</key>
<string>Add</string>
</dict>
</array>Add a toolbar item
The SFSafariToolbarItem dictionary adds a toolbar item to Safari windows. See Toolbars for design guidelines.
[Image]
Each app extension can have only one toolbar item. The value for this key is a dictionary that describes the toolbar item. There are four required keys for the toolbar item dictionary.
Subkey | Type | Description |
|---|---|---|
| String | Required. A string identifier for the toolbar item. This doesn’t display to the user. |
| String | Required. A string that appears in the overflow menu, in the Customize palette, and on hover. |
| String | Required. A string specifying the filename of a scalable PDF image. The image must be transparent. Add the image file to your extension’s Xcode target. |
| String | Required. A string specifying the command to send when the user clicks the toolbar item. Available actions are |
Here’s an example dictionary in XML:
<dict>
<key>Action</key>
<string>Command</string>
<key>Identifier</key>
<string>Button</string>
<key>Image</key>
<string>Toolbar.pdf</string>
<key>Label</key>
<string>My Item</string>
</dict>Use the Image key to provide an image for the toolbar button. Safari may resize or recolor the toolbar button image when drawing it to the screen. Make your image a template image and follow the guidelines for toolbar items.