To programmatically transform text on paste in macOS using BetterTouchTool (BTT) or Keyboard Maestro (KM), you can leverage their scripting and automation features to intercept clipboard content, apply transformations, and paste the modified text. Here’s how you can achieve this with each tool:
BetterTouchTool (BTT)
BTT allows you to define custom JavaScript transformer functions that can process clipboard content before pasting. Here’s a step-by-step guide:
-
Create a JavaScript Transformer Function
-
Assign the Transformer to a Shortcut or Clipboard Action
- Assign a keyboard shortcut to trigger the transformer.
- Alternatively, use BTT’s Clipboard Manager to apply the transformation automatically when pasting.
-
Optional: Use "Transform & Replace Selected Text With JavaScript"
- This action will replace the currently selected text in any app with the transformed version, making it seamless to use in your workflow[12][16].
Example Use Case:
Transform all-caps text to title case automatically on paste:
- Copy text (e.g., "HELLO WORLD").
- Trigger your BTT macro (via shortcut or clipboard manager).
- The macro pastes "Hello World" instead of the original[16].
Keyboard Maestro (KM)
Keyboard Maestro provides powerful macros for clipboard and text manipulation using its "Filter Variable" action and scripting support.
-
Create a Macro for Text Transformation on Paste
- Set up a macro triggered by a hotkey or clipboard change.
- Use the "Set Variable to Clipboard" action to capture clipboard content.
- Apply a "Filter Variable" action to transform the text (e.g., lowercase, uppercase, title case, custom regex).
- Set the clipboard to the transformed text.
- Use the "Paste" action to insert the modified text[7][13][17].
-
Example Macro Steps:
- Copy selected text.
- Transform using a filter (e.g., "Capitalize Each Word").
- Paste the transformed text, replacing the original selection.
-
Advanced: Custom Scripting
- For more complex transformations, use KM’s "Execute JavaScript for Automation" or "Execute Shell Script" actions to process the text before pasting[17].
Example Use Case:
Automatically convert pasted text to sentence case:
- Select and copy text.
- Trigger your KM macro.
- Macro transforms and pastes the text in sentence case, replacing the original selection[7][13].
Comparison Table
| Feature | BetterTouchTool (BTT) | Keyboard Maestro (KM) |
|---|
| Scripting Language | JavaScript (async functions) | Built-in filters, AppleScript, JS, Shell |
| Trigger Options | Hotkey, Clipboard Manager, Selection Change | Hotkey, Clipboard Change, Palette |
| Transformation Scope | Clipboard, Selected Text, Floating Menus | Clipboard, Selected Text, Palettes |
| Example Transformations | Title Case, Regex, AI (ChatGPT), Shell Script | Title Case, Regex, Filters, Scripting |
| Ease of Use | Visual UI, JavaScript snippets | Visual UI, Built-in filters, scripting |
Tips
- Both tools work best with plain text. Formatting (rich text) may be lost depending on the app and method used[8].
- For advanced needs (e.g., AI-based transformations), BTT can integrate with ChatGPT or run custom scripts[12].
- Assign your macro or transformer to a convenient hotkey for quick access.
Summary
- BetterTouchTool: Use JavaScript transformer functions to process clipboard or selected text, then paste the transformed result. Highly customizable and scriptable[11][12][16].
- Keyboard Maestro: Use macros with built-in filters or custom scripts to transform clipboard content before pasting. Flexible and easy to set up for a variety of text manipulations[7][13][17].
Both tools are excellent for automating text transformations on paste in macOS. Choose based on your preferred scripting language and workflow style.