-
-
Save GitMurf/817a6c9e73e1d1e312fc1a1735edb8d6 to your computer and use it in GitHub Desktop.
<%* | |
//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); | |
} | |
%> |
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.
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;
Thanks for this. Is there a way to disable the time and date stamp?
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);
Hi. How can i quick capture an idea to my today - daily note? thank you.
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.
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)