In a previous article, I used Obsidian’s QuickAdd to create a script that automatically converts text copied from ChatGPT and fixes the LaTeX formatting. However, there is no suitable plugin available for the Craft app.
We can use Raycast to achieve this functionality uniformly.
Create a Raycast Script
First, we need to create a script.
Next, select the Bash template.
Then, we edit the Bash script and enter the following code:
#!/bin/bash
# Required parameters:
# @raycast.schemaVersion 1
# @raycast.title Copy From ChatGPT
# @raycast.mode silent
# Optional parameters:
# @raycast.icon 🤖
# @raycast.packageName ChatGPT Utils
# Documentation:
# @raycast.description Copy From ChatGPT
# @raycast.author Nansen Li
# @raycast.authorURL nansenli.com
# Get clipboard content
clipboard_content=$(pbpaste)
# Check if content was successfully retrieved
if [ -z "$clipboard_content" ]; then
echo "Clipboard is empty or inaccessible."
exit 1
fi
# Process clipboard content
modified_content=$(echo "$clipboard_content" | \
sed 's/\\\[/$$/g; s/\\\]/$$/g; s/\\( /$/g; s/ \\\)/$/g')
# Write the modified content back to the clipboard
echo "$modified_content" | pbcopy
After creating the script, we need to add the directory containing the script to Raycast.
In this step, select the directory where the script was just created. At this point, we can see the newly created script in Script Commands
.
How to Use
After copying a formula from ChatGPT, open the Raycast panel, find the newly created script, and run it. The clipboard content will be automatically fixed. Then, simply paste it into Obsidian or Craft.