Please help create a simple script

Hello,
My father has been collecting quotes (personal ones that are memorable to him) for the past 20 years. He has them scribbled down in a very old and dilapidated notebook. I have taken this notebook (shhh, it’s a surprise!) and digitized it. I purchased an iPad for his 88th birthday made the font bigger and downloaded Drafts 4 to it.

Currently, the quotes are located in a text file in Dropbox. Please, I need your help. I can export the entire document, but typing each quote each note by note in Drafts will take me a year (ugh). Is it possible to do this by URL or javascript? I searched the action directory and could not find anything that would do it

[b]. It would help me a great deal a script could separate the text by Linebreak (next line). so for example. The quotes file has thousands and thousands of quotes

Quotes.txt
Line1
Line2
Line3

>>> Drafts script >>>

LINE 1 - First draft note

LINE 2 - First draft note

LINE 3 - First draft note

I don’t know Javascript and don’t know enough about URL scheems to do this myself.
Please let me know either way if you can help me and thank you in advance (and for the wonderful program)

1 Like

This is certainly doable with a script, but are you sure you want them broken up into individual drafts? It might well be easier to search for them in that form, but my first thought is that it would be easier to have them in a single file or draft with blank lines separating each quote.

It really depends on how you think your father will use the quotes. Either way could work, I just don’t want you caught with them in a form that you and he are unhappy with.

The required Javascript is pretty short. Assuming you import the “Quotes.txt” into a single, draft, an action with this script would split that draft into individual drafts, one per line:

let lines = draft.content.split("\n");
for (let line of lines) {
    let d = Draft.create();
    d.content = line;
    d.update();
}

Hi guys,
Thank you so much for the quick responses. You guys are amazing!

agiletortoise: when I run that script I get
“Javascript Error”
“ReferenceError: Can’t find variable: Draft”

(I am running latest version of Drafts 4)

Drdang,

That is a very valid point. I agonized over this part of the request for about an hour. The reason I wanted to break it up into individual drafts is for the following reasons:

  1. I want him to be able to search using iPad spotlight function (this is a dealbreaker as I can’t pull individual quotes into spotlight when they’re not in the title of the draft)
  2. His eyesight isn’t the best. Reading the desired quote in individual format. I know you can increase the font in draft, but I thought it would be easier to read quotes 1 by one.
  3. Would make it easier to add new quotes too

Sorry, missed the Drafts 4 part. This is not possible in Drafts 4. Drafts 4 has much more limited scripting capabilities - it can not create new drafts via script.

1 Like