Skip to main content
added 227 characters in body
Source Link
Manngo
  • 3.7k
  • 12
  • 40
  • 66

I have written a solution which has worked well for some time.

  1. Open Automator and create a new workflow. I called mine InputUnicode.
  2. Check these settings:
    • Workflow receives no input
    • any application
    • ☑︎ Output replaces selected text
  3. 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:

  1. System Preferences
  2. Keyboard | Shortcuts
  3. 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:

enter image description here

I have written a solution which has worked well for some time.

  1. Open Automator and create a new workflow. I called mine InputUnicode.
  2. Check these settings:
    • Workflow receives no input
    • any application
    • ☑︎ Output replaces selected text
  3. 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:

  1. System Preferences
  2. Keyboard | Shortcuts
  3. 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.

I have written a solution which has worked well for some time.

  1. Open Automator and create a new workflow. I called mine InputUnicode.
  2. Check these settings:
    • Workflow receives no input
    • any application
    • ☑︎ Output replaces selected text
  3. 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:

  1. System Preferences
  2. Keyboard | Shortcuts
  3. 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:

enter image description here

Source Link
Manngo
  • 3.7k
  • 12
  • 40
  • 66

I have written a solution which has worked well for some time.

  1. Open Automator and create a new workflow. I called mine InputUnicode.
  2. Check these settings:
    • Workflow receives no input
    • any application
    • ☑︎ Output replaces selected text
  3. 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:

  1. System Preferences
  2. Keyboard | Shortcuts
  3. 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.