In Windows, enclosing text with delimiters using a keyboard shortcut (see examples below) can be achieved using a AutoHotkey script.
- Ctrl " : adds double quotes to the phrase
- Ctrl ' : adds single quotes -- do --
- Ctrl ] : adds square brackets -- do --
- Ctrl ) : adds parentheses -- do --
#Requires AutoHotkey >=v2.0
; Function to enclose selected text
EnclSelText(openChar, closeChar) {
A_Clipboard := ""
SendEvent "^c"
if ClipWait(0.1) {
cSelected := A_Clipboard
Send openChar cSelected closeChar
}
}
; Hotkeys with different enclosures
^)::EnclSelText("(", ")")
^]::EnclSelText("[", "]")
^"::EnclSelText('"', '"')
^'::EnclSelText("'", "'")
The above can be achieved using Automator; steps described below.
- Automator → New → Quick Action
- Drag action Run Shell Script from Library to the right pane
- Right pane settings:
- Set to "Automatic (text)"
- Enable "Output replaces selected text"
- Set
/bin/bash
- Pass input "as arguments"
- In the box, add
echo "($1)"
- Save as Enclose parentheses. (Gets saved in ~/Library/Services folder.)
- From System Settings → Keyboard shortcuts → Services → Text → Click on Enclose parentheses, and hit Ctrl 0, click Done
This above would now make the action available in any application.