Parse existing draft into predefined template

Hi!

When taking notes on stuff I read, I use a template that looks something like this

YMDHM The title
title: The title
tags: #inbox #andperhapssomeothertag
source: URL
timestamp: YMDHM
- - - 
My note, often with some 
> markdown quotes 

The reason for Title being duplicates on the first two lines (and with a time stamp in the first) is that I use the title + time stamp as filename when saving to Dropbox.

Now, my question is how I most easily create a note like this in Drafts. For notes I take when reading a book or a newspaper, I’ve a TextExpander snippet with the template. But I also do a lot of reading in my RSS reader and in Pocket - and I suspect things could Ben automated quite a bit using the apps’ share extension as a starting point, and then selecting Drafts.

The problem is that the content in the new draft is not based on my wanted template. Sharing from Pocket, as a example, creates a draft like this:

http://getdrafts.com/
Drafts. Where Text Starts.

That is, the source URL on line 1 and the article’s title on line 2 (which, by the way, is not the title I want to use in my note - where I want to use a title of my own thoughts, not the source). And, if there is something I want to quote, I’ve copied it before I press Share and paste it on line 3 and onwards and also add my own thoughts.

Now - what’s the easiest way to go from (input)

The Title
http://getdrafts.com/
Drafts. Where Text Starts.
> Some quotes text that might or might not span more then a line.
Followed by my own notes one one or more lines.

to (output)

YMDHM The title
title: The title
tags: #inbox #andperhapssomeothertag
source: URL
timestamp: YMDHM
- - - 
> Some quotes text that might or might not span more then a line.
Followed by my own notes one one or more lines.

All notes created will have the #inbox tag, and in some cases I add more. The time stamp should be created automatically, based on date and the current time. The Title I add manually at some step in the process and have that duplicate at both the first and second line of the output draft.

What I have in mind is a solution where I switch to Drafts and have a script that takes the input, parse it and creates the output. But I have no idea on how to do this. Any suggestions? Even better if this script could be executed from the Share sheet so I don’t have to switch to Drafts and back to Pocket to continue to read.

This is way beyond what I ever have done with Drafts so any help are appreciated!

1 Like

This should be possible but not through the share sheet - see Action Extension “Run Drafts Action”

Since it is whole lines you’re working with, you can just use some of the built in content tags to rearrange your content which makes things a lot simpler than it might otherwise be. Content tags can also be used to access (and format) the draft creation time which takes care of your timestamp requirement. You can use Javascript to concatenate the tags into the desired format and then update the draft content with the reformatted content

Here’s an action that does the formatting:

Below is the Javascript that makes this work.

Javascript Source Code
//Build first line - time index & title
let strFormattedContent = draft.processTemplate("[[created|%Y%m%d%H%M]]") + " " + draft.processTemplate("[[line|1]]") + "\n";
//Build title line
strFormattedContent += "title: " + draft.processTemplate("[[line|1]]") + "\n";
//Build tags line
strFormattedContent += "tags: #inbox #andperhapssomeothertag" + "\n";
//Build source line
strFormattedContent += "source: " + draft.processTemplate("[[line|2]]") + "\n";
//Build time index line
strFormattedContent += "timestamp: " + draft.processTemplate("[[created|%Y%m%d%H%M]]") + "\n";
//Build separator line
strFormattedContent += "- - -\n"
//Append remaining quote and personal notes lines
strFormattedContent += draft.processTemplate("[[line|4..]]");
//Replace the original draft content with the new reformatted content
draft.content = strFormattedContent;
draft.update();

You would run this action on your ‘input’ draft.

If you wanted to save your initial content and run the action on it immediately you would need to use something else as an interim. For example, I’ve set up this Workflow app workflow as a share extension that allows you to pass in some text, pass the text on to Drafts *and* run the reformatting action immediately.

You mention at some point in the process you would tag the draft. You could modify the action or workflow to prompt you for additional tags prior to the reformatting. Note also that Drafts supports tags as meta data for the draft and so you might also find it useful to create your tag entries as fully fledged Drafts tags assigned to the draft.

Hope that helps.

1 Like