Introducing Extension Snippets

PopClip 2021.11 introduced a new, simple way to create and share your own extensions, which I am calling Extension Snippets.

EDIT, 13 Oct, 2023: Snippets now have their own page in the PopClip documentation here: Snippets

It is easiest to show with examples, so without further ado, here is an extension snippet:

# popclip
name: Emojipedia
url: https://emojipedia.org/search/?q=***

Select that text above, and you’ll see an “Install Extension” action in PopClip:

CleanShot 2021-11-16 at 17.51.09

Wait, what just happened?!:exploding_head:

You installed a new extension in PopClip just by selecting some text! This particular extension will search Emojipedia for the selected text.

Hopefully you are starting to realise the possibilities. You can now create your own extensions just by typing text in a text field and selecting it. You can do it anywhere you can type text — in the TextEdit app, in your favourite notes app, anywhere you like.

For example, you can go ahead and change the name and the URL from the example above to anything you like, to create your own search extension (keeping the *** as the search query placeholder).

Extension snippets are also easy to share with others, since you can put them anywhere you can put text.

NOTE: When typing a snippet in this forum, you’ll need to format it as Preformatted Text (using the toolbar button, or use three backticks ``` on the lines before and after)

I need to know more :teacher:

The format of an extension snippet is actually the same as for a regular extension — which is all documented in detail here.

A snippet must start with the first line # popclip (with or without the space) and must be no more than 1000 5000 characters.

The snippet uses a format called YAML to define the extension’s properties such as its name, icon, and to define its action. If that sounds complicated, don’t worry. Usually you can just copy one of the examples and edit it.

Snippets can be used for all types of PopClip extension, except Shell Script extensions. So you can use snippets to open URLs, run Shortcuts, call Services, press keys, run AppleScripts, and run JavaScript code.

Adding an icon :artist:

Let’s go back to the Emojipedia example. Let’s say we want to give it an icon. We can do this as follows:

# popclip
name: Emojipedia
icon: search filled E
url: https://emojipedia.org/search/?q=***

You’ll see I added the line icon: search filled E. This gives the action a magnifying glass icon with an E in it:

Instead of a magnifying glass you can put it in a circle or a square, filled or not filled. And using symbol:<symbol name> you can use macOS’s built in SF Symbols icons. Here are some examples:

Next steps :foot:

Rather than make this post really long, I’m going to be posting in this forum some “How To” guides with examples of various types of extension (see below).

Please use the PopClip Extensions forum category to post snippets you’ve made that might be useful to others.

Hopefully, that whetted your appetite for the possibilities of Extension Snippets. Stay tuned for more to come.

Snippet Guides

19 Likes

Wow. That was easy! A super simple modification for your “Remove Spaces” extension, called “Remove Dots”

# popclip
name: Remove Dots
icon: square filled dot
javascript: popclip.pasteText(popclip.input.text.replace(/\./g, ''))
description: Remove dots from the selected text.
2 Likes

Love it! It’s kind of surprising how easy it is isn’t it :slight_smile: Really happy you were able to put it together. My aim with this has been to distill the extensions down to their simplest form without all the XML files and identifiers and extra gubbins that used to be needed, so that more people can create their own extensions.

p.s. I took the liberty of editing your opening backticks as ```yaml to make the syntax highlighting nice. An alternative is ```text to get all one colour.

edit: I’ve now set ```text as the default on the forum.

3 Likes

This is wonderful, great work!!

1 Like

Bugger. I accidentally deleted my previous post when I was trying to copy it to share in the new subforum. Please find it here: Remove Dots

1 Like

I have magic powers :sparkles:

1 Like

8 posts were split to a new topic: Allocine search

Hey Nick - thinking back on the icon limitation and the other thread where you asked about updated snippet length… If you did increase the snippets to 3000-5000 chars, could you also support base64 encoded text for icons? Then I could do icon: iVBORw0KGgoAAAANSUhEUgAAAI[…]AAAACACAYAAADDP==. I guess the issue would still be the total character limit…

1 Like

@brokosz Yes icons as data does make sense. As you say, it would have to go along with an increased snippet size limit, to make sense. It’s just the snippets wouldn’t be quite so ‘snippety’ any more… I did say I would think about this but I didn’t do anything about it for 2022.5.

That said, I do have what I think is a really good idea to enable a lot more icons in snippets. Say tuned…

P.S., welcome to all PopClip users viewing this thread for the first time! many of you may only be discovering the snippets feature now due to the recent PopClip update mentioning it in the release notes.

I’ve just added a new guide: How to run a macOS Shortcut from PopClip

3 Likes

With the latest PopClip update, snippets gained new capabilities. I wrote a new post about it:

3 Likes