Shortcuts Integration
Run macOS Shortcuts with your selected text.
How It Works
OnText can trigger any Shortcut from the Shortcuts app, passing the selected text as input.
Setting Up
- Create a Shortcut in the Shortcuts app
- In OnText, create a new action
- Select Shortcut as the action type
- Enter the exact name of your Shortcut
Examples
Create a Shortcut
- Open Shortcuts app
- Click + to create a new shortcut
- Add actions to process text input
- Where the selected text should go, set it to receive Shortcut Input
- Save with a memorable name
Example Shortcuts
Add to Notes:
- Shortcut receives text as input
- "Create Note" action with input as body
Translate Text:
- Shortcut receives text as input
- "Translate Text" action
- "Show Result" or "Copy to Clipboard"
Summarize with AI:
- Shortcut receives text as input
- "Use Model" action (for AI summarization)
- "Show Result" action
Passing Text to Shortcuts
OnText passes selected text as Shortcut Input. In your Shortcut:
- Use "Shortcut Input" variable to access the text
- Process it with any Shortcut actions
- Optionally return a result
Advanced: Getting Results Back
You can call Shortcuts from a Shell Script and use the returned value. Here's an example that uses a Shortcut for language detection:
#!/bin/zsh
API_KEY="your-api-key-here"
API_URL="https://api-free.deepl.com/v2/translate"
INPUT_TEXT='{text}'
# Detect language using Shortcuts
DETECTED_LANG=$(osascript -e "tell application \"Shortcuts\" to run shortcut \"detect lang\" with input \"$INPUT_TEXT\"" 2>/dev/null)
# Translate based on detected language
if [[ "$DETECTED_LANG" == "Korean" ]] || [[ "$DETECTED_LANG" == "ko" ]]; then
TARGET_LANG="EN-US"
else
TARGET_LANG="KO"
fi
# Call translation API
RESULT=$(/usr/bin/python3 -c "
import sys, json, urllib.request
text = '''$INPUT_TEXT'''
api_key = '$API_KEY'
url = '$API_URL'
target_lang = '$TARGET_LANG'
data = {'text': [text], 'target_lang': target_lang}
headers = {'Authorization': f'DeepL-Auth-Key {api_key}', 'Content-Type': 'application/json'}
try:
req = urllib.request.Request(url, data=json.dumps(data).encode('utf-8'), headers=headers)
with urllib.request.urlopen(req) as response:
print(json.loads(response.read().decode('utf-8'))['translations'][0]['text'], end='')
except Exception as e:
print(f'Error: {e}', end='')
" 2>&1)
echo -n "$RESULT" | pbcopy
sleep 0.1
osascript -e 'tell application "System Events" to keystroke "v" using command down'
Pro Tip
This pattern lets you leverage Shortcuts for tasks that are easier to configure visually (like language detection, text recognition, etc.) while still using Shell Scripts for complex processing!
Limitations
- Shortcut must exist in your Shortcuts app
- Name must match exactly (case-sensitive)
- Complex Shortcuts may take longer to execute