Add tags to "split draft" action

I use the Split at delimiter action, created by @nahumck, quite a bit. But I have two requests:

First, my original draft usually has tags, because I often work in a specific workspace. How do I modify the action to make sure the newly created drafts carry the same tags as the original, so they all appear in the same workspace?

Second, the action works from beginning to end, so if the body of the original draft contains:

“A|B|C”

the new drafts appear in reverse order in my folder:

C
B
A
Original draft

Is it possible to modify the action to split the new drafts off starting with the last occurrence of the delimiter first?

This may seem trivial, but it’s a pain in the butt to work with several drafts, each with an action item, in reverse order in my folder.

By the way, thanks to Nahumck for your wonderful contributions to the Drafts actions directory!

I can’t speak for the tags but for the ordering of your drafts in the ‘folder’, that’s actually something you might be able to manage in the workspace settings. Take a look at my screenshots below and you can see the ordering options available.



1 Like

Something like this? (Try replacing the script in the existing action with the script below; two minor adjustments for your queries…)


// Split at specified delimiter

var delim = "|";

var text = draft.content;
// reverse handling of array:
var chunks = text.split(delim).reverse();
for (var chunk of chunks) {
	var d = Draft.create();
	d.content = chunk;
	// push tags from source to new drafts
	for (let i in draft.tags) {
	d.addTag(draft.tags[i]);
	}
	d.update();
} 

1 Like

Works perfectly. Thanks so much!

1 Like