Some people on the Raycast Slack were asking about how to use PopClip with Raycast AI to replace selected text with the AI’s response. I figured I’d share one solution here for anyone else interested.
To do things like replace selected text, you can use my PromptLab extension and install the “Ask AI & Replace Selection” command from the command store. You don’t have to use Raycast AI; the extension can be configured to use any API endpoint. Then you can use the following extension snippet to run the command from PopClip:
#popclip extension snippet to replace the selected text with output from Raycast AI
name: Replace With AI Response
icon: AI
applescript: do shell script "open -g raycast://extensions/HelloImSteven/promptlab/search-commands?arguments=%7B%22commandName%22:%22Ask%20AI%20%26%20Replace%20Selection%22%7D"
AppleScript and open -g
are used to ensure that Raycast properly gets the selection from the target app (rather than trying to get it from itself).
To make your own command using a predefined prompt, you can select the PromptLab command and do ⌘K
⌘D
(Create Derivative) to make a copy of the command above, then add your prompt at the start. E.g., you could change the prompt to {{js:paste(`Summarize this: {{prompt:{{selectedText}}}}\`.trim())}}
Here are some other extension snippets and their corresponding PromptLab commands:
Ask AI & Copy to Clipboard
#popclip extension snippet to send selected text to PromptLab and copy its output
name: Copy AI Response
icon: square AI
applescript: do shell script "open -g raycast://extensions/HelloImSteven/promptlab/search-commands?arguments=%7B%22commandName%22:%22Ask%20AI%20%26%20Copy%20to%20Clipboard%22%7D"
Summarize Selected Text
#popclip extension snippet to summarize the selected text using AI
name: Summarize With AI
icon: Summarize
applescript: do shell script "open -g raycast://extensions/HelloImSteven/promptlab/search-commands?arguments=%7B%22commandName%22:%22Summarize%20Selected%20Text%22%7D"