I have written a solution which has worked well for some time.
- Open Automator and create a new workflow. I called mine
InputUnicode
.
- Check these settings:
- Workflow receives no input
- any application
- ☑︎ Output replaces selected text
- Add the
Run JavaScript
action.
The JavaScript is:
function run(input, parameters) {
var app = Application.currentApplication()
app.includeStandardAdditions = true
var input = app.displayDialog('Unicode HEX:', {
defaultAnswer: '',
withIcon: 'note',
buttons: ['Cancel', 'OK'],
defaultButton: 'OK'
}).textReturned
var text='';
input.split(' ').forEach(i=>{
text+=String.fromCodePoint(parseInt(i,16)||63);
});
return text;
}
I then assigned a universal shortcut ⌥⌘U:
- System Preferences
- Keyboard | Shortcuts
- Services | InputUnicode (Same as above)
The workflow pops up an input box which allows you to enter one or more space-separated hex codes. These codes are converted into unicode characters, or question marks if not possible, and the result is inserted into the text.
I wrote it in JavaScript because I understand it better than AppleScript, though the API documentation is pretty hard to find.
Annoyingly, the only application this doesn’t work with properly is Firefox, which doesn’t seem to handle the shortcut. However, you can still get to it through the Firefox | Services menu.
Update
I have now added this to Github: https://github.com/manngo/input-unicode.
You end up with a simple popup like this:
cha
(茶, \8336) definitely needs Unicode input. On Windows the only way to enter smart quotes is via unicode input. The Mac is normally smarter than that …