DYI AI Text "Cleaner"
Adam
Posted on February 3, 2024
I was looking through hacker news an saw this post about some app. The App will take any highlighted text and "enhance" it using chatgpt after the user does some keybinding. And then lower someone said that they just created a script it do it for them and save $$ a month.
So I said screw it, I'll do it myself as well and started chatting with my personal E2 engineer, ChatGPT.
(I'm clicking a keyboard shortcut to make this generate)
Setting up the bash script
First off if you don't have jq installed make sure you have it.
brew install jq
Create a folder somewhere easy to access and store your script. For the past of this guide it will be ~/ai_text_cleaner
.
mkdir ~/ai_text_cleaner
Now download my script to that folder.
wget -O ~/ai_text_cleaner/ai_text_cleaner https://raw.githubusercontent.com/nrgapple/scripts/main/ai_text_cleaner/ai_text_cleaner
Next add a .env
file in the directory and add your OpenAI key to it.
OPENAI_API_KEY=[your-key-here]
Last we need to make the script executable.
chmod +x ~/ai_text_cleaner/ai_text_cleaner
Lets test if it works.
~/ai_text_cleaner/ai_text_cleaner "ths is sme text that i wrot poorly and rlly fast to show if you can cln up stuff well."
I get this as a response:
This is some text that I wrote poorly and really fast to see if you can clean up stuff well.
Nice! Lets move on.
Set up Automator on Mac
Run this command to pull down repo, pull out the automator action folder and remove the repo. (I recommend doing this in your ~/Downloads
directory.
git clone https://github.com/nrgapple/scripts.git && mv scripts/ai_text_cleaner/automator/AI\ Text\ Clean\ Up.workflow ./ && rm -rf scripts
Open up the file ai_text_cleaner/automator/AI Text Clean Up.workflow/Contents/document.wflow
. ctr+f
for ai_text_cleaner
. You should see a line like so:
<string>$HOME/git/scripts/ai_text_cleaner/ai_text_cleaner "$@"</string>
Change it to where you saved your script from above. If you saved it to where I said it would be:
<string>$HOME/ai_text_cleaner/ai_text_cleaner "$@"</string>
Save and Lets move on.
Copy the whole directory (AI Text Clean Up.workflow
) to your services folder in automator:
cp -r AI\ Text\ Clean\ Up.workflow ~/Library/Services/AI\ Text\ Clean\ Up.workflow
Nice. Now last is to create a keybinding for running it.
Set up the keybindings
Go to Settings on Mac and search for Keyboard
. Click Keyboard Shortcuts
.
Click Services
and look for it under the different categories. Mine was under Text
Double click it and set your keybinding.
Nice. You're ready to test it out!
Test it out!
Open a text document and type some sentence or paragraph. Highlight all the text and do your keybinding. It will take a second or two and bam! You should see your highlighted text be replaced by Chatgpt's enhanced cleaning!
Modify the prompt
If you think what Chatgpt gave you sucked, you can try to change the prompt.
In our bash script from above look for this line:
# Define the prompt in a variable
PROMPT="You are a helpful assistant. Your task is to correct any grammatical errors, improve sentence structure, and fix spelling mistakes in the following text."
You can try and change this to your hearts desire to get better results!
Conclusion
We have created a tool worth $6.90 a month! You'll only have to pay for what you use on OpenAI's api rates.
Let me know if something doesn't work for you and I'll make some edits. Let me know if you would like me to do some more DYI AI tools in the future. I have already adapted with flow to create a command line command generator is well (Can be found in the same repo).
Thanks! 👋
Posted on February 3, 2024
Join Our Newsletter. No Spam, Only the good stuff.
Sign up to receive the latest update from our blog.