Add specific phrase before selected text

To start you off, here is how you would insert a string and paste it and add it to the clipboard:

// #popclip
// name: Insert string
// icon: iconify:ic:baseline-insert-comment
// requirements: [paste]
// language: javascript
let fixedString = "My fixed text string\n";
if (popclip.modifiers.command) {
  fixedString = "Alternative string";
}
popclip.pasteText(
  fixedString + popclip.input.text,
  { restore: false } // leave pasted text on the clipboard
);

(The above block is an extension snippet - select the text it then click “Install Extension” when PopClip appears.)

One issue is you will run into if using Shift or Option modifiers has side effects. More info and a solution here.

Demo:
CleanShot 2023-02-06 at 13.09.30

More info here: https://github.com/pilotmoon/PopClip-Extensions#javascript-actions.

p.s. welcome to the forum, @merelybeholding !

1 Like