Drafts Action to remove all OmniFocus tags

As a Drafts and OmniFocus user who is not comfortable in Action creation, I need a Draft action that will find and remove all OmniFocus tags from a draft.

Use case:
I often copy a project as taskpaper, paste it in Drafts, and use it for notes in a project meeting. Some of my projects are fairly extensive, so all the OmniFocus tags can be a little difficult to wade through when all I need is the simple outline.

This may exist, but the overlap and generalness of the search terms is making it hard to find what I need.

Thanks in advance!

When you say ‘tags’ do you mean just the ‘tags’ in an OmniFocus sense, or do you also want to get rid of, for example, the @parallel, @autodone etc information?

I’m sure I’ve seen something like this floating around somewhere (it may have been in Shortcuts actually) but either way it seems like something that should be do-able. :slight_smile:

Yes! The @something(something_else) text is what I need to get rid of. I’m sure someone could do it in Drafts with Regex… I’m just not that person. :).

Maybe a couple of lines like this would suffice?

draft.content = draft.content.replace(/(^\s*-.*?)(\s@.*)$/gm, "$1");
draft.update();

If you add this to a script step, the JavaScript above, when run on a Taskpaper draft like this:

Project 1:
	- Some task @tagged
	- Some double tagged task	@tagged @taggedagain
	- Some other task @completed 2020-04-11 @anothertag

Project 2:
	- Untagged task
		- Tagged sub task with a tag @tag
			Notes with @tags in them
	- This one has an e-mail@address.com in it
	- This one has a quoted "@Twitter_handle"

Project 3 - all about @tags:
	- Another task @tagged

Will strip it down to look like this:

Project 1:
	- Some task
	- Some double tagged task
	- Some other task

Project 2:
	- Untagged task
		- Tagged sub task with a tag
			Notes with @tags in them
	- This one has an e-mail@address.com in it
	- This one has a quoted "@Twitter_handle"

Project 3 - all about @tags:
	- Another task

Note this example includes tags in notes and project sections, as well as other uses of the at symbol such as for e-mail addresses and user handles.

The regular expression match looks for task lines only (lines starting with whitespace followed by a hyphen), and then match the first white space and at symbol (for a tag) that follows, and all the way to the end of the line. That match is then wiped by replacing the content with everything that precedes the whitespace and at symbol.

That leaves in place @ symbols in e-mail addresses (as they won’t be preceded by whitespace, and any tags referenced in projects and notes.

If you need to include any at mentions (e.g. a Twitter handle or an Office 365 user reference), I would recommend putting these in quotes (single, double, back tick - whatever works for you), so that they don’t get flagged up as being a tag for the purposes of this reset (because the at symbol is not immediately preceded by whitespace).

Is that anything like close to what you’re after?

2 Likes

This is perfect. Thank you so much!