Add specific phrase before selected text

Hi All,
My first post and I’m looking for an action that adds specific phrases to the selected text with popclip and then add the two to the clipboard (or simply adds the phrase before the selected text without adding them to the clipboard). It would be great if we can select from among the phrases to add by pressing shift or ctrl keys while clicking the extension icon.

I hope to make use of such an extension for ChatGpt actually:

  1. To specify particular requests in the first post. 2. To “remind” the AI of those requests later with phrases like “continue to follow my previous requests.” 3. To switch to a different request quickly: “Explain the following” for instance versus “is the following correct? Reply without giving further explanations,” and so on…

We don’t need access to the API as this is to be done / pasted on the ChatGpt site… The extension can add phrases before a text in the TextEdit app, for instance, it doesn’t make any difference for my current request (simply: Typing the same reminders numerous times has been quite a waste of time)

I suspect that this is ridiculously easy. I have no idea how to make modifications to the phrases by pressing keys though.

Many thanks!

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

Expectedly brilliant! Many thanks, nick! This extension should be enough to save quite some time (with just one modifier key used, control instead of command) for now. I probably won’t need to change the assigned modifier key functions for now – useful info on the link for future though.