TIP: Using AI for ad-hoc text manipulation

The most compelling use case for AI I’ve found in Drafts is doing advanced, even multi-step, text manipulations. Think of it as a way to create and apply advanced actions to text in the editor without writing any Javascript.

Although the default “chat” mode of working with ChatGPT can be compelling, it can also process very specific tasks for you by constructing the correct prompts. The example action covered in this tip simplifies the process by doing the following:

  • Get the text you currently have selected in the editor
  • Prompt you to enter a phrase describing what task(s) you would like done with this text
  • Construct a prompt for ChatGPT that asks it to perform those tasks on the text
  • Gets back the result and either replaces the selection with it, appends the result, or places the result in the clipboard.

The types of things you can use in the prompt can be simple things. A few examples I’ve used with great success are:

  • “correct spelling”
  • “translate into Spanish”
  • “lowercase”

This gets more powerful when you combine more complex tasks. A few examples, both useful and silly:

  • “Make a Markdown list of the URLs found in this text”
  • “convert HTML to Markdown”
  • “Summarize this text in two sentences”
  • “Reverse the letters in each word, and insert a :+1: emoji between each word”
  • “Replace occurrences of ‘foo’ with ‘bar’”

Obviously, AI is not perfect. It will not always do exactly what you were hoping - but it is often quite accurate. In all cases, a change made by the action can be undone. The action also provides options in the prompt, whether the result should replace your existing text selection, append to the end, or just be placed in the clipboard. Which of these options makes the most sense often depends on tasks you are requesting.

Set Up the “Modify Selection” Action

To get started:

Demo

This brief video shows a couple of example ideas for complex prompts that work great with this action:

4 Likes