Skip to content

Paste clipboard into list of wikilinks #173

ryanjamurphy started this conversation in Templates Showcase
Paste clipboard into list of wikilinks #173
Apr 29, 2021 · 2 comments

General use case: If you copy a list of wikilinked items in Preview, then paste it into Edit mode, you lose the wikilinks. It can be tedious to replace them. This Templater template solves that problem!

My use case: I have a Dataview query for my daily note that shows the notes I edited yesterday. I want to preserve that list as a record, so each day I have a ritual where I copy the list and paste it into the previous day's note. I copy the list, then use this Templater template to insert it into the previous note.

<%*
var clipboard = await tp.system.clipboard();
clipboardLines = clipboard.match(/[^\r\n]+/g);
wikilinkList = "";
clipboardLines.forEach(element => wikilinkList = wikilinkList + "- [[" + element + "]]\n");
this.app.workspace.activeLeaf.view.editor.replaceSelection(wikilinkList);
%>

The section in my daily note template containing the dataview query:

## Last modified yesterday:
⚠️ Copy and paste these into yesterday's Daily Note. ⚠️
```dataview
LIST
FROM "" 
WHERE date({{date-1d:YYYY-MM-DD}}T23:59) - file.mtime <= dur(24 hours) and date({{date-1d:YYYY-MM-DD}}T23:59) - file.mtime > dur(0 hours)
SORT file.mtime asc

Replies

Thanks - I was looking for a solution for both of these problems, and this solves both elegantly.

0 replies

This is awesome, super-creative use of Templater!

Since date(today) will give you the start of today, I think you can simplify your WHERE clause a little bit:

WHERE file.mday >= date(today) - dur(1 day) AND file.mday < date(today)
0 replies
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
3 participants