Extension snippet with AppleScript not accepted

Hi, looking at some posts on “Show & Tell” I noticed that javascript can be used on extension snippets, so I supposed that AppleScript can be used too and I tried a very simple one that should save the clipboard, copy selected text and set the clipboard to the old one + a couple of new lines + the new one. That’s what I wrote:

# popclip
name: Copy+
icon: symbol:plus.square.on.square
applescript: set firstPart to the clipboard

set secondPart to "{popclip text}"

set the clipboard to firstPart & "

" & secondPart

It doesn’t work: instead of “Install Extension” I see “Invalid YAML”. I don’t know if that’s something wrong with the snippet or if AppleScript is simply not supported and I should create the extension with old method (creating popclipext file).
invalid yaml

1 Like

Maybe this helps:

1 Like

Extension snippets are in a format called YAML. YAML is quite particular about the formatting of multi-line strings. You’ll need to start with a pipe (|) character and indent the lines with two spaces.
You also need to use \n for the newline character in a string.

Rewriting it as:

# popclip
name: Copy+
icon: symbol:plus.square.on.square
applescript: | 
  set firstPart to the clipboard
  set secondPart to "{popclip text}"
  set the clipboard to firstPart & "\n" & secondPart

seems to work well.

By the way, this extension already exists: Append to Clipboard — PopClip Extensions

1 Like

Thank you Nick! I was pretty sure this extension already existed but I haven’t been patient enough searching for it, and I was quite curious to try the new extension snippet method.
Anyway I’m gonna use your original version, but I’m curious about one more thing: is it possible to use an image file as an icon with extension snippets? Maybe writing an address in order to find it on the Mac?

1 Like

It’s not possible, but this is something I would like to explore

2 Likes