Create custom text transformation

Solution 1:

Make an Automator service which accepts text and use the following AppleScript action:

      

on run {input}
    return "(" & (input as string) & ")"
end run

Solution 2:

You can also create ~/Library/Keybindings/ and save a property list like this as ~/Library/Keybindings/DefaultKeyBinding.dict:

{
  // option-9 to wrap with parentheses
  "~9" = (setMark:, moveBackward:, insertText:, "(", swapWithMark:, moveForward:, moveForward:, insertText:, ")", moveBackward:);
}

Quit and reopen applications to apply the changes.

See http://osxnotes.net/keybindings.html or https://github.com/ttscoff/KeyBindings/blob/master/DefaultKeyBinding.dict for more examples.