Skip to content

Repository files navigation

PopClip Extensions

Documentation for PopClip 1.4.5

Introduction

PopClip extensions add extra actions to PopClip.

Screenshot showing extensions in use.

This repository contains the documentation for making your own extensions (this readme file) as well as the source files for the extensions published on the main PopClip Extensions page. Layout of the repo:

docs/ -- Image files and resources referred to in this README file.
extensions/ -- Distributable versions of the extensions (zipped, with `.popclipextz` extension).
source/ -- Source files for the extensions. Without the `.popclipext` suffix. Index.plist -- The main page is auto-generated using Index.plist to specify the contents.
LICENSE -- MIT License text.
PopClipExtension.xcodeplugin -- Plist definition file for use with Xcode or PlistEdit Pro.
README.md -- This documentation.

License

All extension source files are published under the MIT License (see LICENSE) unless noted otherwise in the readme files of individual extensions.

Credits

All the extensions and documentation were created by Nick Moore except where stated. Contributor credits are are shown in the readme file of each individual extension.

Contributing

Contributors, please note the following:

  • If you contribute an extension, I will assume you are happy for me to publish your contributions on the main PopClip extensions page.
  • I might not publish your extension. I choose which extensions to publish at my sole discretion.
  • I may make changes to any extension.
  • Please do not edit the Index.plist file.
  • Don't worry about signing the extension, I will take care of that.

Other Repos

Here are some other repos you might find interesting:

Disclaimer

These instructions are designed to help a technically competent person to create their own PopClip extension. Please note that user-created extensions are not an officially supported part of PopClip. You need to be comfortable with creating and editing plist files, scripts, and so on.

I reserve the right to change or remove features in future versions of PopClip at any time.

Extension Signing

By default, PopClip will display a warning dialog when you try to install your own extension, because it is not digitally signed by Pilotmoon Software.

Example unsigned warning.

If you find this gets annoying while you are testing your work, you can turn off the warning. Run the following command at the Terminal, then Quit and restart PopClip:

defaults write com.pilotmoon.popclip LoadUnsignedExtensions -bool YES

Please be aware that PopClip extensions can contain arbitrary executable scripts. Be careful about the extensions you create, and be wary about loading extensions you get from someone else. Proceed at your own risk.

General Overview

Types of Actions

There are five main kinds of actions supported by PopClip extensions.

Action TypeDescriptionExample
ServiceInvoke a Mac OS X Service, passing the selected text.MakeSticky
AppleScriptRun an AppleScript, with the selected text embedded.Evernote
Shell ScriptRun a shell script, with the selected text passed as an environment variable.Say
URLOpen an HTTP URL, with the selected text URL-encoded and inserted.GoogleTranslate
KeypressPress a key combination.Delete

Filtering

All extensions have access to the following filtering mechanisms, to help prevent them appearing when they are not useful:

  • Filter by matching a regular expression.
  • Filter by application (either include or exclude).
  • Filter by whether cut, copy or paste is available.
  • Filter by whether the text contains a URL, email address or file path.

Anatomy of a PopClip Extension

About .popclipextz files

For distribution on the PopClip Extensions page, extensions are zipped and renamed with the extension .popclipextz. You can examine an existing PopClip extension by renaming it with a .zip extension and unzipping it, to reveal a .popclipext package.

The .popclipext package

A PopClip extension consists of a property list called Config.plist, plus (optional) additional files such as the icon and any required scripts, all contained in a directory whose name ends with .popclipext. Such a directory will be treated as a package by Mac OS X. To view the contents of a package, right click it in Finder and choose 'Show Package Contents'.

If you double-click a .popclipext package, PopClip will attempt to load and install it. PopClip stores its installed extensions in ~/Library/Application Support/PopClip/Extensions/.

Here is an example package structure, using the 'Say' extension:

Say.popclipext -- Containing folder
_Signature.plist -- Signature (official Pilotmoon extensions only)
Config.plist -- Main configuration file
say.sh -- Script file
speechicon.png -- Icon file

The Config.plist

Every extension must contain a Config.plist file. This should be an XML-format plist. The plist contains information about the extension, and also defines one or more actions. You can generate a blank plist with Xcode or use this example as a basis: ExampleConfig.plist. Alternatively, use a dedicated plist editor such as the excellent PlistEdit Pro. Here is an example of the plist for 'Translate Tab', as viewed in Xcode:

Example plist, for 'Translate Tab'.

Icons

Extensions may include icons to represent actions. The icon is displayed in the PopClip popup itself, and also in the preferences window and on the web site (if published). Icons may be created in any graphics program. (I use Pixelmator.) The icon should:

  • be a PNG file
  • be square
  • be at least 256x256 pixels
  • consist of solid black figure on a transparent background

For example, here is the full-size icon file for 'Sort':

The 'Sort' icon (256x256 PNG file)

Configuration Details

General

  • All key names are case sensitive.
  • Make sure that you set each field the correct type. A common error is to enter a number as a string type.

"String or Dictionary" type

Fields with the type "String or Dictionary" can take either a String or Dictionary value. If you supply a string value, that string is always used. Alternatively, you can supply a dictionary mapping language code (en, fr, etc.) to a string. PopClip will display the appropriate string for the user's preferred language if possible, with fallback to the en string.

Config.plist Structure

The Config.plist file has the following structure.

KeyTypeRequired?Description
Extension IdentifierStringRequiredProvide a string which uniquely identifies this extension. Use your own prefix, ideally a reverse DNS-style prefix. For example com.example.myextension. Do not use the prefix com.pilotmoon. for your own extensions.
Extension NameString or DictionaryRequiredThis is a display name that appears in the preferences list of extensions.
Extension Image FileStringOptionalFile name of the icon to represent this extension in the preferences window. The icon file must be contained in the extension package. If you omit this field, the icon for the first action will be used (if any), or else no icon will be displayed. See Icons for required icon format.
Blocked AppsArrayOptionalArray of bundle identifier strings (e.g. com.apple.TextEdit) of applications for which this extension's actions should not appear.
Required AppsArrayOptionalArray of bundle identifier strings of applications required for this extension's actions to appear.
Regular ExpressionStringOptionalA Regular Expression to be applied to the selected text. The action will appear only if the text matches the regex. Furthermore, only the matching part of the text is used in the action. The default regex is (?s)^.{1,}$ (note that (?s) turns on multi-line mode). The engine used is RegexKitLite.
RequirementsArrayOptionalArray consisting of one or more of the strings listed in Requirements keys. If this field is omitted, the default is copy.
Stay VisibleBooleanOptionalIf YES, the PopClip popup will not disappear after the user clicks the action. Default is NO.
Preserve Image ColorBooleanOptionalIf YES, the image file will be draw in its original color, instead of in white.
Pass HTMLBooleanOptionalIf YES, PopClip will pass the selected HTML text (if available) to the extension in the POPCLIP_HTML (shell scripts) and {popclip html} (AppleScript) fields. Default is NO. Leaving this set to NO PopClip does not have to process the HTML and this can be slightly faster.
Long RunningBooleanOptionalApplies to AppleScript and Shell Script extension only. If YES, indicates that the script is expected to be long running. Set this if the script will normally take more than about 0.1 seconds to run, so PopClip knows to show the 'please wait' spinner.
Extension DescriptionString or DictionaryOptionalA short, human readable description of this extension.
Extension Long NameString or DictionaryOptionalYou can include a long version of the extension name here. Appears on the web site but not in the app.
CreditsArrayOptionalAn array of dictionaries. Information about the creator(s) of the extension. See Credits Dictionary.
AppsArrayOptionalAn array of dictionaries. Information about the app(s) this extension works with. See Apps Dictionary.
Required OS VersionStringOptionalMinimum version number of Mac OS X needed for this extension to work. For example 10.8.2.
Required Software VersionNumberOptionalMinimum bundle version number of PopClip needed for this extension to work. For example 701 for PopClip 1.4.5.
ActionsArrayRequiredArray of dictionaries defining the actions for this extension. See Action Dictionary.
OptionsArrayOptionalArray of dictionaries defining the options for this extension, if any. See Option Dictionary.
Options TitleString or DictionaryOptionalTitle to appear at the top of the options window. Default is Options for this extension..

Action Dictionary

Each action dictionary has the following structure. Exactly one of Service Name, AppleScript File, Shell Script File, URL or Key Combo should be specified.

KeyTypeRequired?Description
TitleString or DictionaryRequiredFormat is as for Extension Name above. Note that every action must have a title, even if it is never displayed.
Image FileStringOptionalFile name of the icon for this action in PopClip. The icon file must be contained in the extension package. If you omit this field, the Title will be displayed instead. See Icons for required icon format.
Service NameStringRequired for Service actionsExact name of the OS X service to call (as shown in the Services menu). For example, Make Sticky.
AppleScript FileStringRequired for AppleScript actionsThe name of the AppleScript file to use. The file must exist in the extension's package. The script must be a plain text file (save as .applescript, not .scpt) and it must be saved using UTF-8 encoding. Within the script, use "{popclip text}" as the placeholder for the selected text. Other fields are also available: see Script Fields. See also Example AppleScript File.
Shell Script FileStringRequired for Shell Script actionsThe name of the shell script file to invoke. The file must exist in the extension's package. This will be passed as the parameter to /bin/sh. Within the script, use the environment variable $POPCLIP_TEXT to access the selected text. Other variables are also available: see Script Fields. The current working directory will be set to the package directory. See also Example Shell Script File.
Script InterpreterStringOptionalSpecify the interpreter to use for the script specified in Shell Script File. The default is /bin/sh but you could use, for example, /usr/bin/ruby.
URLStringRequired for URL actionsThe URL to open when the user clicks the action. Use {popclip text} as placeholder. For example, http://translate.google.com/#auto%7Cauto%7C{popclip text}. Any & characters must be XML-encoded as &.
Key ComboDictionaryRequired for Keypress actionsSpecify the keypress which will be generated by PopClip. See Key Code format.
BeforeStringOptionalString to indicate an action PopClip should take before performing the main action. See Before and After keys.
AfterStringOptionalString to indicate an action PopClip should take after performing the main action. See Before and After keys.
Blocked AppsArrayOptionalAs above; this value overrides the value specified in the extension header.
Required AppsArrayOptionalAs above; this value overrides the value specified in the extension header.
Regular ExpressionStringOptionalAs above; this value overrides the value specified in the extension header.
RequirementsArrayOptionalAs above; this value overrides the value specified in the extension header.
Stay VisibleBooleanOptionalAs above; this value overrides the value specified in the extension header.
Preserve Image ColorBooleanOptionalAs above; this value overrides the value specified in the extension header.
Pass HTMLBooleanOptionalAs above; this value overrides the value specified in the extension header.
Long RunningBooleanOptionalAs above; this value overrides the value specified in the extension header.

Requirements keys

These are the values supported by the Requirements field. Additionally, you can prefix any requirement with ! to negate it. For example, !paste if you only want the action to appear when Paste is not available.

ValueDescription
copyThe system Copy command must be available (that is, the Copy item in the Edit menu must not be greyed out).
cutThe system Cut command must be available.
pasteThe system Paste command must be available.
formattingThe selected text control must support formatting.
httpurlRequire the text to contain exactly one HTTP(S) URL; only the matching part will be passed to the action.
httpurlsRequire the text to contain one or one HTTP(S) URLs.
anyurlRequire the text to contain exactly one URL of any detected type; only the matching part will be passed to the action.
anyurlsRequire the text to contain one or one URLs of any detected type.
emailRequire the text to contain exactly one email address; only the matching part will be passed to the action.
pathRequire the text to contain exactly one local file path; only the matching part will be passed to the action.
htmlSelection must be HTML text (for example, text in a web page).
option-*=#The option named * must be equal to the string #. For example option-fish=1 would require an option named fish to be set on. This mechanism allows actions to be enabled and disabled via options.

Before and After keys

These are the values supported by the Before and After fields.

ValueDescription
cutPerform system Cut command, as if user pressed ⌘X.
copyPerform system Copy command, as if user pressed ⌘C.
pastePerform system Paste command, as if user pressed ⌘V.
paste-plainStrip the system pasteboard down to plain text only, then perform system Paste command, as if user pressed ⌘V.
popclip-appearMakes PopClip invoke itself again. (This is used in the Select All extension).
copy-selectionCopy the originally selected text as plain text. (This is used in the Swap extension.)
copy-resultCopy the text returned from the script script to the clipboard. Displays "Copied" notification. If there is no text, or the script failed, shows an 'X'.
paste-resultIf the system Paste command is available, paste the text returned from the script, as well as copy it to the clipboard. Otherwise, only copy it as in copy-result. If there is no text, or the script failed, shows an 'X'.
preview-resultCopy the text returned from the script to the clipboard, and show the result as well (truncated to 100 characters). If the system Paste command is available, the preview text can be clicked to paste it. If there is no text, or the script failed, shows an 'X'.
show-resultShow the text returned from the script. If there is no text, or the script failed, shows an 'X'.
show-statusShow a tick or a 'X', depending on whether the script succeeded ort not.

Option Dictionary

Options are presented to the user in a preferences window and are saved by PopClip's preferences on behalf of the extension. Each option dictionary has the following structure.

KeyTypeRequired?Description
Option IdentifierStringRequiredUnique identifying string for this option. It must be an all-lowercase string. This field is used to pass the option to your script. (See Script Fields.)
Option TypeStringRequiredOne of the following: string (text box for free text entry), boolean (a check box) or multiple (pop-up box with multiple choice options).
Option LabelString or DictionaryRequiredLabel to appear in the user interface for this option.
Option Default ValueStringOptionalFor string, boolean and multi types, this field specified the default value of the option.
Option ValuesArrayRequired for multiple typeArray of strings representing the possible values to show in the pop-up button.

Script Fields

These strings are available in Shell Script and AppleScript extensions. Where no value is available, the field will be set to an empty string.

Shell Script VariableAppleScript FieldDescription
POPCLIP_TEXT{popclip text}The selected text, without formatting.
POPCLIP_URLENCODED_TEXT{popclip urlencoded text}URL-encoded form of the selected text. For example, if the selected text is push / pull this field will contain push%20%2F%20pull.
POPCLIP_HTML{popclip html}The selected text in HTML format, if available. The Pass HTML field must be set to YES to receive this field.
POPCLIP_MODIFIER_FLAGS{popclip modifier flags}Modifier flags for the keys held down when the extension's button was clicked in PopClip. Values are as defined in Key Code format. For example, 0 for no modifiers, or 131072 if shift is held down.
POPCLIP_BUNDLE_IDENTIFIER{popclip bundle identifier}Bundle identifier of the app the text was selected in. For example, com.apple.Safari.
POPCLIP_APP_NAME{popclip app name}Name of the app the text was selected in. For example, Safari.
POPCLIP_BROWSER_TITLE{popclip browser title}The title of the web page that the text was selected from. (Safari and Chrome only.)
POPCLIP_BROWSER_URL{popclip browser url}The URL of the web page that the text was selected from. (Safari and Chrome only.)
POPCLIP_OPTION_*(all UPPERCASE){popclip option *}(all lowercase)One such value is generated for each option specified in Options, where * represents the Option Identifier. For boolean options, the value with be a string, either 0 or 1.

Credits Dictionary

KeyTypeRequired?Description
NameStringRequiredName or identifier of the contributor. For example John Smith.
LinkStringOptionalA link to the contributor's website or other URL. For example http://johnsmith.com

Apps Dictionary

KeyTypeRequired?Description
NameStringRequiredName of the app which this extension interacts with. For example Evernote for an Evernote extension.
Check InstalledBooleanOptionalIf YES, PopClip will check whether the app given by Bundle Identifier is installed when the user tries to use the extension. If missing, PopClip will show a message and a link to the website given in Link. Default is NO.
LinkStringRequired if Check Installed is YESLink to a website where the user can get the app referred to in Name. For example http://evernote.com.
Bundle IdentifierString or ArrayRequired if Check Installed is YESBundle identifier of the application. For example com.evernote.Evernote. If an app has multiple variants, for example, Pro and Free variants, or if an app use a different bundle ID for the App Store version to the stand-alone version, then include all the possible bundle IDs as an array.

Additional Notes

Example AppleScript File

Important: AppleScript files must be in UTF-8 plain text format. (Save as 'text' format in AppleScript editor.)

Here is an example of an AppleScript file for use in an extension (this one is for sending to Evernote):

tell application "Evernote"
activate
set theNote to create note with text "{popclip text}"
open note window with theNote
end tell

Example Shell Script File

Here is an example of an shell script for use in an extension (this one is for 'Say'):

echo $POPCLIP_TEXT | say

Script Returning Result

Scripts can return results if they specify one of the *-result or show-status keys in the Action's After field.

Scripts should indicate success or failure as follows. If the script indicates a failure with settings, it will cause the extension's options window to appear (if it has one).

ResultShell ScriptAppleScript
SuccessReturn status code 0Return without raising an error
General failureReturn status code 1Raise error with code 501. Example AppleScript: error "any text" number 501.
Failure with settingsReturn status code 2Raise error with code 502. Example AppleScript: error "any text" number 502.

Here is an example of a Ruby script that could be used in a shell script extension (with the Script Interpreter set to /usr/bin/ruby) and the After key set to paste-result.

input=ENV['POPCLIP_TEXT']
# make the text ALL CAPS
print input.upcase 

See also the Uppercase extension for a working example.

Key Code format

Key presses should be expressed as a dictionary with the following keys:

KeyTypeRequired?Description
keyCharString(see note below)Character key to press. For example A.
keyCodeNumber(see note below)Virtual key code for key to press. For example, the delete key is 51. For help finding the code see this StackOverflow question.
modifiersNumberRequiredBitmask for modifiers to press. Use 0 for no modifiers. Shift=131072, Control=262144, Option=524288, Command=1048576. Add together the values to specify multiple modifiers (see table below).

Note: Exactly one of keyChar or keyCode should be specified. Not both.

Table of modifier combinations:

KeysValue
none0
131072
262144
⌃⇧393216
524288
⌥⇧655360
⌃⌥786432
⌃⌥⇧917504
1048576
⇧⌘1179648
⌃⌘1310720
⌃⇧⌘1441792
⌥⌘1572864
⌥⇧⌘1703936
⌃⌥⌘1835008
⌃⌥⇧⌘1966080

About

Documentation and source code for all Pilotmoon's PopClip extensions.

Resources

Stars

0 stars

Watchers

0 watching

Forks

Releases

Packages

Contributors

Languages