Skip to content

Instantly share code, notes, and snippets.

@GitMurf
GitMurf / query-todo-daily.js
Last active October 16, 2020 23:31
Query TODO due dates, filtering out Daily Note page
//v0.3
//To apply TODO filter, use Shift + Click on the query syntax when a query is loaded with results
//Use this link to see GIF of DEMO: https://user-images.githubusercontent.com/64155612/95497690-9c0f8680-0957-11eb-94a7-e0cd49d62a06.gif
//The goal of this script is to filter out TODOs that only show up because they were added on daily notes page
//Mainly it is if you want to find overdue tasks, like from the last week, by default a TODO due next week will still
//show up if you added that TODO on a daily notes page from last week (within the between range)
//Resources about the script:
//For detailed discussion, see this Slack thread: https://roamresearch.slack.com/archives/C012WK8E9DK/p1601992542022100
//Here is my github repo: https://github.com/GitMurf/roam-javascript
@GitMurf
GitMurf / filter-focus.js
Last active March 12, 2021 16:46
Roam JavaScript to focus on search box when opening a filter
document.addEventListener('click', function (evt) {
if (evt.target.className === 'bp3-icon bp3-icon-filter') {
function sleep(ms) {
return new Promise(resolve => setTimeout(resolve, ms));
}
async function removeFilters(event) {
var filteredButtons = event.target.parentElement.parentElement.parentElement.getElementsByTagName('BUTTON')
if (filteredButtons.length == 0 || filteredButtons == null) { return }
@GitMurf
GitMurf / obsidian.templater.pull-line.js
Last active May 5, 2021 22:43
Pull a line to the active file from a specified file without having to open it.
<%*
//v1.2: For block refs / embeds need to add line breaks above and below otherwise block ref extends to lines around it
//"pull" = default: removes the line, "pull-copy" leaves line, "pull-embed" leaves embed, "pull-ref" adds block ref
const pullMode = "pull";
const pullFromFile = await tp.system.suggester((item) => item.path, this.app.vault.getMarkdownFiles(), false);
if(pullFromFile) {
let cmEditorAct = this.app.workspace.activeLeaf.view.editor;
@GitMurf
GitMurf / obsidian.templater.block-ref.copy-alias.js
Created May 25, 2021 06:27
Creates block ref on current line and copies to clipboard as asterisk alias link to be pasted somewhere else
<%*
const curSelection = tp.file.selection();
const cmEditorAct = app.workspace.activeLeaf.view.editor;
const curLineNum = cmEditorAct.getCursor().line;
const curLine = cmEditorAct.getLine(curLineNum);
cmEditorAct.setSelection({ line: curLineNum, ch: 0 }, { line: curLineNum, ch: 9999 });
const blockRef = curLine.match(/ \^(.*)/);
let id;
if (!blockRef) {
<%*
const dateFormat = "YYYY-MM-DD";
const dateBasisStr = await tp.system.prompt("When is the meeting?");
if (dateBasisStr) {
function createMessage(daysBefore, dateFormat, dateBasisStr) {
let parseResult;
let newDate;
let parseResultLink;
let nlDatesPlugin = app.plugins.getPlugin('nldates-obsidian');
<%*
//v0.3 - Allow for Include and Exclude variables to have multiple criteria -- Define Qty of results
//VARIABLES TO SET
//How many results to return
const howMany = 1;
//Include the "#" for tags and brackets "[" for pages
const pageOrTag = "#quote";
//The Including and Excluding variables are arrays []. To add multiple values use format: ["one","two"]
//This is a plain text filter of the resulting blocks
@GitMurf
GitMurf / obsidian.templater.search.tasks.current-page.js
Created August 26, 2021 03:31
Run this templater script to open the Search sidebar and search for all open Tasks on the current page
<%*
const search = app.workspace.getLeavesOfType("search")[0];
let thisFile = app.workspace.getActiveFile();
search.view.setSortOrder("byCreatedTime");
search.view.setCollapseAll(false);
search.view.setExtraContext(true);
let myString = thisFile.basename;
search.view.setQuery(`file:("${myString}") task-todo:(/^./)`);
app.workspace.revealLeaf(search);
%>
<%*
const search = app.workspace.getLeavesOfType("search")[0];
search.view.setSortOrder("byCreatedTime");
search.view.setCollapseAll(false);
search.view.setExtraContext(true);
const dnp = tp.date.now('YYYY-MM-DD');
const dnp2 = tp.date.now('YYYY_MM_DD');
let myString = `((file:${dnp2} task-todo:"[ ]") OR ((/Due Date: .*\\[\\[${dnp}\\]\\].*/ OR /due date: \\[[0-9, -]*${dnp}[0-9, -]*\\]/) task-todo:"[ ]") OR (file:${dnp} task-todo:"[ ]") OR (task-todo:"${dnp}") OR section:(/^\#.*${dnp}/ "[ ]") OR section:(/^\#.*${dnp}/ section:("[ ]"))) -file:("weekly review")`;
search.view.setQuery(`${myString}`);
app.workspace.revealLeaf(search);