Run Shell Script on Selected Text on Mac
OnText can run a shell script with the text you selected in the current Mac app. This is useful when a small command is faster than copying text into Terminal, running a script, then pasting the result back.
The workflow is: select text, press F2, then trigger your shell script action.
Basic Shell Action
Create a Shell Script action in OnText and use {text} where the selected text should be inserted:
echo '{text}' | tr '[:lower:]' '[:upper:]' | pbcopy
This copies an uppercase version of the selected text to the clipboard.
Replace Text After Processing
Use OnText placeholders when you want to process text and paste it back:
echo '{text}' | tr '[:lower:]' '[:upper:]' | pbcopy && {paste}
The command transforms the selection, writes it to the clipboard, then uses {paste} to paste the result.
Safer Placeholder Options
OnText supports multiple placeholders for different cases:
{text}for fast selected text capture.{textWithCopy}when an app needs copy-based selected text capture.{clipboard}for the current clipboard.{prompt}to ask for extra input before running the action.{date},{time}, and{datetime}for timestamped workflows.
Read the placeholders guide before building scripts that modify text in place.
Good Use Cases
Shell script actions are useful for:
- Formatting identifiers such as snake_case or CONSTANT_CASE.
- Cleaning whitespace or line breaks.
- Sending selected text to a local command-line tool.
- Building small clipboard transformations.
- Combining selected text with prompts or dates.
For more examples, see Shell Scripts and Custom Actions.
