Clip selection to Obsidian

Perfect! Thanks much :slight_smile:

1 Like

Any help would be deeply appreciated. You’ll are doing something I am missing.

I installed the extension but when I try to clip something, it opens the correct Vault but to the most recent accessed note (not specifically the Daily Note) and it does not add any content. What might I be missing?

Yes, I have the Obsidian URI plugin and daily notes and have created a Clippings heading in my daily note template.

If the obisidian://advanced-uri?... link does not work for you, the best way to troubleshoot it is to create the link manually – say in TextEdit or other plain text context – and test it apart from the PopClip extension. File in the fields in the test URL with dummy text. If the test URL created this way still does not work, then make sure your Daily Note and Advanced URI plugin settings in Obsidian are correct. If that still results in error, then open a ticket with the devleoper of the Advanced URI plugin.

The PopClip extension in @nick’s revision here works. Errors are most likely on the user side.

1 Like

Indeed… simple problem - I installed but did not activate the URI plugin.

Works fine now.

Thanks

Here’s my version

# PopClip superhuman with link to obsidian
name: SHEntry
icon: circle S
capture html: true # this is needed when we want markdown text
javascript: |
  let clipping = popclip.input.markdown
  popclip.pressKey('/', util.constant.MODIFIER_CONTROL)
  clipping += `\n[Email link](${pasteboard.text})`
  clipping = encodeURIComponent(clipping)
  popclip.openUrl(`obsidian://advanced-uri?vault=notes&filepath=/fleeting/note&data=%0A${clipping}`)

The pasteboard.text returns the clipboard content prior to running the snippet. The script copies the correct link but that is not added to the clipping. Instead it remains in the clipboard after the snippet is run. I’m sure I’m missing something obvious :thinking:

Also, is there a way to dynamically change the created note filename each time this is run (e.g. using timestamp)?

The pasteboard.text returns the clipboard content prior to running the snippet.

I’m guessing that the code is reading the clipboard too soon, before Superhuman has had a chance to actually place its link on there it.

The code to add a delay might be a little bit jarring to look at if you aren’t used to JavaScript callbacks:

# PopClip superhuman with link to obsidian
name: SHEntry
icon: circle S
capture html: true # this is needed when we want markdown text
javascript: |
  let clipping = popclip.input.markdown
  popclip.pressKey('/', util.constant.MODIFIER_CONTROL)
  setTimeout(function() {
    clipping += `\n[Email link](${pasteboard.text})`
    clipping = encodeURIComponent(clipping)
    popclip.openUrl(`obsidian://advanced-uri?vault=notes&filepath=/fleeting/note&data=%0A${clipping}`)
  }, 500)

The number 500 sets a delay of 500 milliseconds (half a second) – you might want to try other values, I haven’t actually tested it because I don’t have Superhuman installed.

That works just right! Thanks :slight_smile:
As I no longer need the append function, I just changed to the Obsidian URL to generate a new file:

popclip.openUrl(`obsidian://new?vault=notes&file=fleeting/&content=%0A${clipping}`)
1 Like

That works just right! Thanks :slight_smile:

Great!

If you want to dynamically generate a date string JavaScript can do that… I can’t remember off the top of my head but I’m about to update the Timestamp extension so that shoulld refresh my memory.

1 Like

Speaking of experimenting, I’m trying to modify the scripts in this thread to create a new full note in Obsidian. Everything works except for line 18 (let fname = popclip.input.markdown.slice(0, 20) ) where I’m trying to name the file with the beginning of the selected text for non-html text. I feel like I’m missing something obvious.

Edit: cleaner code with better header creation

# PopClip - Obsidian new note
name: OBClipper
icon: symbol:text.badge.plus
options:
- identifier: vault
  label: Vault Name
  type: string
capture html: true
javascript: | 
  const vaultName = encodeURIComponent(popclip.options.vault)
  let clipping = popclip.input.markdown
  if (popclip.context.browserUrl.length > 0) { 
    let title = encodeURIComponent(popclip.context.browserTitle)
    clipping += `\n[${popclip.context.browserTitle}](${popclip.context.browserUrl})\n#clipped`
    clipping = encodeURIComponent(clipping)
    popclip.openUrl(`obsidian://advanced-uri?vault=${vaultName}&filepath=${title}.md&data=%23%20${title}%0A${clipping}`)
  } else {
    let fname = popclip.input.markdown.split(' ').slice(0, 7).join(' ')
    clipping = `# ` + fname + `\n` + clipping + `\n#clipped`
    fname = encodeURIComponent(fname)
    clipping = encodeURIComponent(clipping)
    popclip.openUrl(`obsidian://advanced-uri?vault=${vaultName}&filepath=${fname}.md&data=%0A${clipping}`)
  }
1 Like

The snippet wouldn’t load for me because it’s 1032 characters - I edited your post to remove a comment to get it under the 1000 character limit. After that it seems to work OK and my selection was shortened to 20 characters.

:man_facepalming: thanks @nick. I don’t think I would have figured that out on my own.

I think I shall add a visible message when the snippet is too long

5 posts were split to a new topic: Snippet length discussion

Hi, Thanks for the scripts. However, it seems that it fails to extract url when using it in Arc browser. It works well in Chrome and Safari, but sadly not with Arc. Do you know if there is a way of fixing that?

Hi @nick , any help would be greatly appreciated!

Hi, unfortunately PopClip does not support extracting the URL from Arc browser yet.

Hi and thanks for sharing @nick and @EdM .

I’ve made an Obsidian plugin that works with the extension snipept you shared.

Here is the Github repository of Obsidian Popclip plugin

1 Like

Thanks for this @webmeister . I’ve installed the Obsidian plugin, and also add your version of this snippet into PopClip.

I have a few questions for you, if you don’t mind:

  1. What’s the purpose of the Obsidian plugin? Does it mean Advanced URI plugin is no longer a requirement?
  2. You have added a Location to your popclip snippet. What is the purpose of that? I assumed, perhaps wrongly, that it was to enable adding the cilpped text to any folder in the Vault, rather than it being added by default to the daily folder. But that doesn’t appear to be the case.

I came here for two reasons.

The first is to say: thank you for this miracle of an app. Among the best purchases I have made haha. Really exceptional.

The second is to add my +1 to “send to Obsidian.” I followed the instructions on @webmeister’s repo for the plugin but it does not appear to be working for me.

1 Like