Grab URL of Selected Text?


I want to write an extension that not only grabs and exports the selected text but also the URL of the page. I saw there is a shell variable for getting the URL, but I don’t think a shell script is the best way to go about this task. My goal is to send the selected text to another app (let’s use Tot for example) and append the URL for context. Is there an easy way to do this? Thank you!

1 Like

The easiest way to do this is with a JavaScript extension. The URL is in the global popclip.context.browserUrl.

So, for example:

// #popclip
// name: Tot with URL
// language: javascript
let text = `${popclip.input.text}\n${popclip.context.browserUrl}`;
popclip.openUrl("tot://1/append?text=" + text);

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


Thanks so much, nick!

1 Like