Idea: Paste with reference

Hi, I wonder whether it would be possible to paste text with the original link. For example, I copy some text from a website or a pdf file to Word, and it could follow the web link/ the pdf address at the end of the text in Word. Thanks.

4 Likes

That’s a great suggestion… it wouldn’t be possible as a “Paste as…” action but it could be done with a “Copy as…”.

The following should do the trick:

# popclip extenison to copy with source link
name: Copy with Link
icon: symbol:link.circle.fill
before: copy
javascript: |
  if (popclip.context.browserUrl.length > 0) {
    pasteboard.text = pasteboard.text.trim() + '\n\n' + popclip.context.browserUrl
  }

(The above block is an extension snippet - select it to install the extension with PopClip)

The javascript code checks to see if there is a browser URL available and if so appends two newlines followed by the URL to the text on the pasteboard.

3 Likes

That’s a really useful extension - I love it! Not knowing much javascript, I wanted to ask how the script can be changed to make it possible to copy text plus images rather than just trimming the copied text before pasting. Is that easy to do?

1 Like

Having spent the last hour looking through the documentation online, I realise that that is not an easy thing to do! So, please ignore my question.

Aha, yes the processing capabilities are very much text focused. It would be nice to be able to more gracefully hande images one day. Thanks for the question and welcome to the forum @Paul_Thompson

Love it!! Can you make it a markdown link?

1 Like

To make it a markdown link you would change

popclip.context.browserUrl

to

'[' + popclip.context.browserTitle + '](' + popclip.context.browserUrl + ')'

You can also markdownify the whole thing with something like this:

# popclip extenison to copy markdown with source link
name: MD Copy with Link
icon: symbol:link.circle.fill
capture html: true
javascript: |
  let text = popclip.input.markdown
  if (popclip.context.browserUrl.length > 0) {
    text += '\n\n[' + popclip.context.browserTitle + '](' + popclip.context.browserUrl + ')'
  }
  popclip.copyText(text)
1 Like

You are amazing! Thank you so much!! Stan

1 Like

This isn’t working for me. All I get in the clipboard is the selected text, and no url. I did modify the code slightly to fix a typo and change the icon, but the original doesn’t work either.

What I have so far:

# popclip extension to copy with source link
name: Copy with Link
icon: square filled Ref
before: copy
javascript: |
  if (popclip.context.browserUrl.length > 0) {
    pasteboard.text = pasteboard.text.trim() + '\n\n' + popclip.context.browserUrl
  }

What browser are you using? Nick’s version works fine for me in Chrome.

Well, duh. It works in Safari, not in Firefox (I only use Chrome as a last resort). I had already enabled PopClip in System Prefs/Security & Privacy/Accessibility. Don’t see anything relevant in FF prefs, and did try turning off an ad blocker. Good thing I normally use Safari.

Suggestions welcome, but not desperate.

Thanks!

By the way - a slight tweak to add quotes to the beginning and end of the pasted text:

# popclip extension to copy with source link
name: Copy with Link
icon: symbol:link.circle.fill
before: copy
javascript: |
  if (popclip.context.browserUrl.length > 0) {
    pasteboard.text =  '\"' + pasteboard.text.trim() + '\"' + '\n\n' + popclip.context.browserUrl
  }
1 Like

Ahhh - yes unfortunately it won’t work in Firefox. Firefox doesn’t offer a way to obtain the current page URL (other browsers have an AppleScript interface for this but Firefox does not)

Good to know. In Safari, my tracker blocker interferes—but only sometimes? Still, it’s useful!