0

I have created three keyboard shortcuts to right-click menu items on my Mac that work in any application:

When text is selected:

Capitalize is Ctrl+C

Make Lower Case is Ctrl+L

Make Upper Case is Ctrl+U

Makes sense but now that is laid out I'd like to create an Applescript to invoke these shortcuts with just the CAPS key.

What I'd like is:

When text is selected:

Double-click CAPS invokes Ctrl+C

If text is UC single click CAPS invokes Ctrl+L

If text is LC single click CAPS invokes Ctrl+U

Otherwise CAPS acts as normal.

Is there a way to do this? Keyboard Settings wouldn't allow me to use CAPS as a hotkey/shortcut.

Braiam
  • 1
  • 11
  • 47
  • 78

2 Answers2

0

I think this is going to be hard if not impossible to do. I have written Applescripts in the past to detect caps lock down or up.(one such as this) But they are clunky to setup. And require other components to be running and then even if i used or wrote an Application in Objective-C it means a third party app has to be running.

The simplest solution is to use your Function keys. You can use three of them one for each

markhunte
  • 6,805
  • 2
  • 25
  • 44
0

You can use PCKeyboardHack to change caps lock to another key (like F19), and then add something like this to private.xml in KeyRemap4MacBook:

<autogen>__DoublePressModifier__ KeyCode::F19, KeyCode::F19, KeyCode::F19, ModifierFlag::COMMAND_L</autogen>

Or for holding the key:

<autogen>__HoldingKeyToKey__ KeyCode::F19, KeyCode::F19, KeyCode::VK_NONE, KeyCode::F19, ModifierFlag::COMMAND_L, Option::NOREPEAT</autogen>

You can use Automator to create a service for converting to lowercase / uppercase. Check output replaces selected text and add a run shell script action like this:

export LC_CTYPE=UTF-8
input=$(cat)
grep -q [[:upper:]] <<< "$input" && \
printf %s "$input" | tr [[:upper:]] [[:lower:]] || \
printf %s "$input" | tr [[:lower:]] [[:upper:]]

You can give it a shortcut (like ⌘F19) in System Preferences.

Automator uses the C locale by default, so without LC_CTYPE=UTF-8 character classes would only include ASCII characters.

Lri
  • 26,768
  • 8
  • 84
  • 82