Text Transform Tools

I’ve made some update to the example Tools action group. The actions can be installed as a new group, or they are all available individually in the action directory as well, if you wish to only install some you are interested in.

The biggest additions include several new multi-function tools which have options related to their function as well as output options to replace text selections, or send result to clipboard or a new draft. These are:

  • Change Case… : For UPPER, lower, Title case transforms.
  • Sort Lines… : For alpha sort, ascending or descending, case-sensitive or not.
  • Encode… : For encoding a selection with either URL Encoding, escaping HTML entities, or Base64.
  • Decode… : For reversing the actions in Decode.

Some other examples for straightening quotes, trimming whitespace and more have been added as well.

If there are other examples of common string transforms you’d like to see, please ask here…will likely create a few more examples. There are many others from the community already in the action directory as well. A few great ones:


Rot13 encoding and decoding? Is that still a thing anymore?

I might be internet-old.

Forgive me if this already exists but is there an action that will permit searching-and-replacing predefined text?

My use case: I’m a journalist and I need to submit articles for publication with a specific HTML style. I need to replace smart quotes and other smart punctuation with their dumb equivalents. em-dashes need to be replaced with two hyphens. HTML entities need to be replaced with their punctuation equivalents. And hrefs need to be set to open in a new window/tab.

I’m looking to create an action that will go through a draft and sequentially search-and-replace on each of those items. I could create it myself but I’d need to have a search-and-replace action that I could use as its basis, and there doesn’t seem to be one.

I’ve used TextSoap for this function for years on the Mac, but I’ve just started using the iPad as my primary computer when I’m away from my office, and so I’m looking to switch to Drafts for that cleanup.


Here’s one approach you might consider.

Create an action with a single script step and put the script below into it. It would then be a case of building out the script to meet your particular requirements.

If you look at the lines starting replaceAll, I’m sure you’ll get the gist of what it is doing, but you just need to produce a big list of what you want to find (first parameter) and what it should be replaced by (second parameter).

I’ve pre-populated the script with smart quotes, em dashes, and a couple of HTML entity examples.

//Define a text replacement function
function replaceAll(p_strFind, p_strReplace)
	let reReplace = new RegExp(p_strFind,"g");
	draft.content = draft.content.replace(reReplace, p_strReplace);

//Replace left and right smart quotes with straight quotes
replaceAll('“', '"');
replaceAll('”', '"');

//Replace em-dash with two hyphens
replaceAll('—', '--');

//Replace ampersand HTML entity with an ampersand
replaceAll('&', "&");
replaceAll('&', "&");

//Replace copyright HTML entity with a copyright symbol
replaceAll('©', "©");
replaceAll('©', "©");
Expand for some extra info

I suspect the draft.update() step might not even be required here, and be applied implicitly at the end. If you find the script becomes slow to run due to complexity and text volume, it might be worth testing without that line in. I think it would only potentially be an issue if you perhaps had an overlap in replacements and then the ordering would become important too.

Of course if you need to actually include anything that the script is automatically replacing for a particular article (e.g. one about replacing text :wink:) , you would need to reapply the details afterwards or forego using the script.

Hope that helps.

BTW, I’d suggest posting queries like this as a new topic as it is only tangentially related to this text transform group and then further discussion around your particular request won’t deviate the original topic.

Very helpful! Thanks so much!

And of course you’re correct about creating a new topic. :slight_smile:

What about a simple sentence case option?