Q: New Draft from Selection

There is an action for New Draft from Each Selected line in the Drafts action directory (http://actions.getdrafts.com/a/1I3) - was trying to find one that would just create a new draft from selection. I know I could select text and share as new draft, but was looking for something cleaner.

May give this a go - but question, would it be easier to start with the New Draft from Each Line script above - or start fresh?

A combination of getSelectedText() and new()?

Thanks for any tips…

I’d say do it from scratch.

Here’s my approach.

  1. Create a new draft.
  2. Set the content of the draft equal to the selected text in the editor.
  3. Update the new draft.
  4. Load the new draft into the editor.
  5. Activate the editor.
Spoiler : this is the code to do it
let newDraft = Draft.create();
newDraft.content = editor.getSelectedText();
newDraft.update();
editor.load(newDraft);
editor.activate();

I may be misunderstanding, but is this not already built in as an option?

Select the text you want to appear in the new Draft, press and hold the “+” and then select New With Selection from the menu displayed.

Indeed, but I’d assumed it was desired as it’s fewer taps if you use an action on the keyboard row and/or include a keyboard shortcut for triggering it. Both quicker ways to trigger.

@wightwizard - Goal was to really minimize the taps - this is an action I tend to do a lot, copying in large sections of text, then snipping parts I want to keep to new Drafts. I know that it would only be two steps with the functionality in drafts - but 50% quicker to use only one tap and have a button in my toolbar to do this.

@sylumer - nice answer and way better than editing the other action - newDraft.content = editor.getSelectedText(); - this was the part I couldn’t get, first tried to store getSelectedText in a variable by itself, but that wasn’t working. Appreciate the help! Action is running…and this will help in other snippets I want to write.

1 Like

If I was pasting into a new draft a chunk of text and then extracting chunks to new drafts I’d want a “cut” semantic, rather than a “copy” semantic. That’s to avoid copying more the same chunk more than once.

Actually an action would ideally allow both - or a pair of actions would cover both cases.

I created a script that is exactly copied and pasted from the script

// See online documentation for examples
// Drafts | Where Text Starts

let newDraft = Draft.create();
newDraft.content = editor.getselectedtext();
newDraft.update();
editor.load(newDraft);
editor.activate();

I get a type error editor,get selected text is not a function.

Am I missing an implied earlier step?

Still works fine for me.

Any chance you used the text you have above rather than copying the original? It isn’t a copy and paste as you suggest.

In the text you have you have the editor method on the second line incorrect as names are case sensitive.

If I use the all lowercase name as posted, as get the following error. Is that the error you are seeing?

Oops!

Thanks. I am not a JavaScript programmer and my normal programming language is not case sensitive.

I changed the second line to

newDraft.content = app.getClipboard()

And am using your script to create a new draft from an iOS shortcut.