Skip to content

Instantly share code, notes, and snippets.

@GitMurf
Last active April 22, 2024 15:14
Show Gist options
  • Star 26 You must be signed in to star a gist
  • Fork 6 You must be signed in to fork a gist
  • Save GitMurf/817a6c9e73e1d1e312fc1a1735edb8d6 to your computer and use it in GitHub Desktop.
Save GitMurf/817a6c9e73e1d1e312fc1a1735edb8d6 to your computer and use it in GitHub Desktop.
Obsidian Quick Capture using templater. Activate from anywhere in your vault to record quick ideas, notes, time logging, etc. The Quick Capture file does NOT need to be open.
<%*
//v1.4: Adding option for including a header for each DNP day to fold
//'first' will add to top of file. 'last' will add to bottom of file
let firstOrLastLine = 'first';
//Name of the Quick Capture file. Do NOT include extension '.md'
let qcFileName = 'Quick Capture';
//Leave this blank if you want to use the default file path location (set to '/' to use root of vault)
let folderOverride = '';
//Add a header for each day to nest the quick capture notes under (only works when firstOrLastLine = 'first')
let bAddHeader = false;
let curDateFormat = '[' + '[' + tp.date.now("YYYY-MM-DD") + ']]';
let finalTimestamp = curDateFormat;
let curTimeFormat = tp.date.now("hh:mm A");
if(curTimeFormat != ''){finalTimestamp = finalTimestamp + ' ' + curTimeFormat}
let qcFolderLocation;
if(folderOverride) {
qcFolderLocation = folderOverride;
} else {
if(this.app.vault.config.newFileLocation != 'current') {
qcFolderLocation = this.app.fileManager.getNewFileParent().path;
} else {
qcFolderLocation = '/';
}
}
if(qcFolderLocation != ''){qcFolderLocation = qcFolderLocation + '/'}
qcFolderLocation = qcFolderLocation.replace(/\/\//g,'/');
if(qcFolderLocation == '/'){qcFolderLocation = ''}
if(qcFolderLocation.startsWith('/')){qcFolderLocation = qcFolderLocation.substring(1)}
let qcFilePath = qcFolderLocation + qcFileName + '.md';
let qcFile = this.app.vault.getAbstractFileByPath(qcFilePath);
if(!qcFile) {
qcFile = await this.app.vault.create(qcFilePath, '');
}
if(qcFile) {
let qcNote = await tp.system.prompt("Enter a Quick Capture note");
let isTodo = qcNote.startsWith(';');
let finalNote = (isTodo ? '- [ ] ' : '') + finalTimestamp + ' - ' + (isTodo ? qcNote.substring(1) : qcNote);
let curContent = await this.app.vault.read(qcFile);
let newContents;
if(firstOrLastLine == 'last'){newContents = curContent + '\n' + finalNote}
else {
if(bAddHeader) {
let curDateHeader = '# ' + curDateFormat;
curContent = curContent.replace('\n' + curDateHeader + '\n\n', '');
newContents = '\n' + curDateHeader + '\n\n' + finalNote + '\n' + curContent;
} else {
newContents = finalNote + '\n' + curContent
}
}
this.app.vault.modify(qcFile, newContents);
}
%>
@GitMurf
Copy link
Author

GitMurf commented Apr 22, 2021

QUICK DEMO: https://user-images.githubusercontent.com/64155612/115743581-a66afe00-a346-11eb-9c38-f25b6ebc4504.mp4

TIP: Copying and pasting into Obsidian as Plain Text seems to work best (ctrl/cmd + shift + v)

@GitMurf
Copy link
Author

GitMurf commented Apr 22, 2021

v1.3: https://gist.github.com/GitMurf/817a6c9e73e1d1e312fc1a1735edb8d6/revisions#diff-8c832395b99eef6755587f9c57a971f4989d39fd7b96f53703fee52626e8fbf1R42

I removed the extra \n line breaks when adding a task/TODO by starting note with ; because it was adding double line breaks if multiple tasks in a row and just didn't look good / normalized.

@GitMurf
Copy link
Author

GitMurf commented Apr 22, 2021

v1.4: https://gist.github.com/GitMurf/817a6c9e73e1d1e312fc1a1735edb8d6/revisions#diff-8c832395b99eef6755587f9c57a971f4989d39fd7b96f53703fee52626e8fbf1R14

Added ability to turn option on to nest each new quick capture entry under a header with the Daily Notes Page link [[DNP]] for each day. Just change to: let bAddHeader = true;

image

@kmaustral
Copy link

Thanks for this. Is there a way to disable the time and date stamp?

@GitMurf
Copy link
Author

GitMurf commented Jun 8, 2021

Thanks for this. Is there a way to disable the time and date stamp?

@kmaustral try to replace this line:

let finalNote = (isTodo ? '- [ ] ' : '') + finalTimestamp + ' - ' + (isTodo ? qcNote.substring(1) : qcNote);

And change it to the following:

let finalNote = (isTodo ? '- [ ] ' : '') + (isTodo ? qcNote.substring(1) : qcNote);

Copy link

ghost commented Apr 1, 2022

Hi. How can i quick capture an idea to my today - daily note? thank you.

@GitMurf
Copy link
Author

GitMurf commented Apr 4, 2022

Hi. How can i quick capture an idea to my today - daily note? thank you.

Please use the QuickAdd plugin instead of this script. This is old. The QuickAdd plugin allows you to do this and so much more and has good documentation.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment