‌‌‌‌‌Get the context of the selected text

Something like this:

// # popclip example of two actions sharing data
// name: Word & Context
// language: javascript
// module: true

let word = null;
let context = null;

function checkInputs() {
  if (word && context) {
    doSomething(word, context);
    // clear inputs for next time
    word = null;
    context = null;
  }
}

function doSomething(word, context) {
    // insert functionality here!
    popclip.showText(`Word is '${word}', context is '${context}'`);
}

exports.actions = [
  {
    title: "Input Word",
    code() {
      word = popclip.input.text;
      checkInputs();
    },
  },
  {
    title: "Input Context",
    code() {
      context = popclip.input.text;
      checkInputs();
    },
  },
];

(The above block is an extension snippet — select it then click “Install Extension” in PopClip.)

2 Likes