Skip to content

Instantly share code, notes, and snippets.

@sbliven
Created December 7, 2022 22:11
Show Gist options
  • Save sbliven/e1c3eed56bcda83090662affa5d78971 to your computer and use it in GitHub Desktop.
Save sbliven/e1c3eed56bcda83090662affa5d78971 to your computer and use it in GitHub Desktop.
Karabiner Elements script to use Fn-<key> for emojis and unicode
#!/bin/zsh
# Restores the clipboard after running unicode_fn.sh
export LC_ALL='en_US.UTF-8'
export LANG='en_US.UTF-8'
sleep .1
pbpaste -pboard ruler | pbcopy
{
"title": "Unicode letters",
"rules": [
{
"description": "Unicode letters with Fn",
"manipulators": [
{
"type": "basic",
"from": {
"key_code": "a",
"modifiers": {
"mandatory": [
"fn"
]
}
},
"to": [
{
"shell_command": "~/.config/karabiner/assets/complex_modifications/unicode_fn.sh.sh a"
}
],
"to_delayed_action": {
"to_if_invoked": [
{
"key_code": "v",
"modifiers": "command"
},
{
"shell_command": "~/.config/karabiner/assets/complex_modifications/restore_pb.sh"
}
],
"to_if_canceled": [
{
"key_code": "v",
"modifiers": "command"
},
{
"shell_command": "~/.config/karabiner/assets/complex_modifications/restore_pb.sh"
}
]
},
"parameters": {
"basic.to_delayed_action_delay_milliseconds": 100
}
},
{
"type": "basic",
"from": {
"key_code": "b",
"modifiers": {
"mandatory": [
"fn"
]
}
},
"to": [
{
"shell_command": "~/.config/karabiner/assets/complex_modifications/unicode_fn.sh.sh b"
}
],
"to_delayed_action": {
"to_if_invoked": [
{
"key_code": "v",
"modifiers": "command"
},
{
"shell_command": "~/.config/karabiner/assets/complex_modifications/restore_pb.sh"
}
],
"to_if_canceled": [
{
"key_code": "v",
"modifiers": "command"
},
{
"shell_command": "~/.config/karabiner/assets/complex_modifications/restore_pb.sh"
}
]
},
"parameters": {
"basic.to_delayed_action_delay_milliseconds": 100
}
},
{
"type": "basic",
"from": {
"key_code": "c",
"modifiers": {
"mandatory": [
"fn"
]
}
},
"to": [
{
"shell_command": "~/.config/karabiner/assets/complex_modifications/unicode_fn.sh.sh c"
}
],
"to_delayed_action": {
"to_if_invoked": [
{
"key_code": "v",
"modifiers": "command"
},
{
"shell_command": "~/.config/karabiner/assets/complex_modifications/restore_pb.sh"
}
],
"to_if_canceled": [
{
"key_code": "v",
"modifiers": "command"
},
{
"shell_command": "~/.config/karabiner/assets/complex_modifications/restore_pb.sh"
}
]
},
"parameters": {
"basic.to_delayed_action_delay_milliseconds": 100
}
},
{
"type": "basic",
"from": {
"key_code": "d",
"modifiers": {
"mandatory": [
"fn"
]
}
},
"to": [
{
"shell_command": "~/.config/karabiner/assets/complex_modifications/unicode_fn.sh.sh d"
}
],
"to_delayed_action": {
"to_if_invoked": [
{
"key_code": "v",
"modifiers": "command"
},
{
"shell_command": "~/.config/karabiner/assets/complex_modifications/restore_pb.sh"
}
],
"to_if_canceled": [
{
"key_code": "v",
"modifiers": "command"
},
{
"shell_command": "~/.config/karabiner/assets/complex_modifications/restore_pb.sh"
}
]
},
"parameters": {
"basic.to_delayed_action_delay_milliseconds": 100
}
},
{
"type": "basic",
"from": {
"key_code": "e",
"modifiers": {
"mandatory": [
"fn"
]
}
},
"to": [
{
"shell_command": "~/.config/karabiner/assets/complex_modifications/unicode_fn.sh.sh e"
}
],
"to_delayed_action": {
"to_if_invoked": [
{
"key_code": "v",
"modifiers": "command"
},
{
"shell_command": "~/.config/karabiner/assets/complex_modifications/restore_pb.sh"
}
],
"to_if_canceled": [
{
"key_code": "v",
"modifiers": "command"
},
{
"shell_command": "~/.config/karabiner/assets/complex_modifications/restore_pb.sh"
}
]
},
"parameters": {
"basic.to_delayed_action_delay_milliseconds": 100
}
},
{
"type": "basic",
"from": {
"key_code": "f",
"modifiers": {
"mandatory": [
"fn"
]
}
},
"to": [
{
"shell_command": "~/.config/karabiner/assets/complex_modifications/unicode_fn.sh.sh f"
}
],
"to_delayed_action": {
"to_if_invoked": [
{
"key_code": "v",
"modifiers": "command"
},
{
"shell_command": "~/.config/karabiner/assets/complex_modifications/restore_pb.sh"
}
],
"to_if_canceled": [
{
"key_code": "v",
"modifiers": "command"
},
{
"shell_command": "~/.config/karabiner/assets/complex_modifications/restore_pb.sh"
}
]
},
"parameters": {
"basic.to_delayed_action_delay_milliseconds": 100
}
},
{
"type": "basic",
"from": {
"key_code": "g",
"modifiers": {
"mandatory": [
"fn"
]
}
},
"to": [
{
"shell_command": "~/.config/karabiner/assets/complex_modifications/unicode_fn.sh.sh g"
}
],
"to_delayed_action": {
"to_if_invoked": [
{
"key_code": "v",
"modifiers": "command"
},
{
"shell_command": "~/.config/karabiner/assets/complex_modifications/restore_pb.sh"
}
],
"to_if_canceled": [
{
"key_code": "v",
"modifiers": "command"
},
{
"shell_command": "~/.config/karabiner/assets/complex_modifications/restore_pb.sh"
}
]
},
"parameters": {
"basic.to_delayed_action_delay_milliseconds": 100
}
},
{
"type": "basic",
"from": {
"key_code": "h",
"modifiers": {
"mandatory": [
"fn"
]
}
},
"to": [
{
"shell_command": "~/.config/karabiner/assets/complex_modifications/unicode_fn.sh.sh h"
}
],
"to_delayed_action": {
"to_if_invoked": [
{
"key_code": "v",
"modifiers": "command"
},
{
"shell_command": "~/.config/karabiner/assets/complex_modifications/restore_pb.sh"
}
],
"to_if_canceled": [
{
"key_code": "v",
"modifiers": "command"
},
{
"shell_command": "~/.config/karabiner/assets/complex_modifications/restore_pb.sh"
}
]
},
"parameters": {
"basic.to_delayed_action_delay_milliseconds": 100
}
},
{
"type": "basic",
"from": {
"key_code": "i",
"modifiers": {
"mandatory": [
"fn"
]
}
},
"to": [
{
"shell_command": "~/.config/karabiner/assets/complex_modifications/unicode_fn.sh.sh i"
}
],
"to_delayed_action": {
"to_if_invoked": [
{
"key_code": "v",
"modifiers": "command"
},
{
"shell_command": "~/.config/karabiner/assets/complex_modifications/restore_pb.sh"
}
],
"to_if_canceled": [
{
"key_code": "v",
"modifiers": "command"
},
{
"shell_command": "~/.config/karabiner/assets/complex_modifications/restore_pb.sh"
}
]
},
"parameters": {
"basic.to_delayed_action_delay_milliseconds": 100
}
},
{
"type": "basic",
"from": {
"key_code": "j",
"modifiers": {
"mandatory": [
"fn"
]
}
},
"to": [
{
"shell_command": "~/.config/karabiner/assets/complex_modifications/unicode_fn.sh.sh j"
}
],
"to_delayed_action": {
"to_if_invoked": [
{
"key_code": "v",
"modifiers": "command"
},
{
"shell_command": "~/.config/karabiner/assets/complex_modifications/restore_pb.sh"
}
],
"to_if_canceled": [
{
"key_code": "v",
"modifiers": "command"
},
{
"shell_command": "~/.config/karabiner/assets/complex_modifications/restore_pb.sh"
}
]
},
"parameters": {
"basic.to_delayed_action_delay_milliseconds": 100
}
},
{
"type": "basic",
"from": {
"key_code": "k",
"modifiers": {
"mandatory": [
"fn"
]
}
},
"to": [
{
"shell_command": "~/.config/karabiner/assets/complex_modifications/unicode_fn.sh.sh k"
}
],
"to_delayed_action": {
"to_if_invoked": [
{
"key_code": "v",
"modifiers": "command"
},
{
"shell_command": "~/.config/karabiner/assets/complex_modifications/restore_pb.sh"
}
],
"to_if_canceled": [
{
"key_code": "v",
"modifiers": "command"
},
{
"shell_command": "~/.config/karabiner/assets/complex_modifications/restore_pb.sh"
}
]
},
"parameters": {
"basic.to_delayed_action_delay_milliseconds": 100
}
},
{
"type": "basic",
"from": {
"key_code": "l",
"modifiers": {
"mandatory": [
"fn"
]
}
},
"to": [
{
"shell_command": "~/.config/karabiner/assets/complex_modifications/unicode_fn.sh.sh l"
}
],
"to_delayed_action": {
"to_if_invoked": [
{
"key_code": "v",
"modifiers": "command"
},
{
"shell_command": "~/.config/karabiner/assets/complex_modifications/restore_pb.sh"
}
],
"to_if_canceled": [
{
"key_code": "v",
"modifiers": "command"
},
{
"shell_command": "~/.config/karabiner/assets/complex_modifications/restore_pb.sh"
}
]
},
"parameters": {
"basic.to_delayed_action_delay_milliseconds": 100
}
},
{
"type": "basic",
"from": {
"key_code": "m",
"modifiers": {
"mandatory": [
"fn"
]
}
},
"to": [
{
"shell_command": "~/.config/karabiner/assets/complex_modifications/unicode_fn.sh.sh m"
}
],
"to_delayed_action": {
"to_if_invoked": [
{
"key_code": "v",
"modifiers": "command"
},
{
"shell_command": "~/.config/karabiner/assets/complex_modifications/restore_pb.sh"
}
],
"to_if_canceled": [
{
"key_code": "v",
"modifiers": "command"
},
{
"shell_command": "~/.config/karabiner/assets/complex_modifications/restore_pb.sh"
}
]
},
"parameters": {
"basic.to_delayed_action_delay_milliseconds": 100
}
},
{
"type": "basic",
"from": {
"key_code": "n",
"modifiers": {
"mandatory": [
"fn"
]
}
},
"to": [
{
"shell_command": "~/.config/karabiner/assets/complex_modifications/unicode_fn.sh.sh n"
}
],
"to_delayed_action": {
"to_if_invoked": [
{
"key_code": "v",
"modifiers": "command"
},
{
"shell_command": "~/.config/karabiner/assets/complex_modifications/restore_pb.sh"
}
],
"to_if_canceled": [
{
"key_code": "v",
"modifiers": "command"
},
{
"shell_command": "~/.config/karabiner/assets/complex_modifications/restore_pb.sh"
}
]
},
"parameters": {
"basic.to_delayed_action_delay_milliseconds": 100
}
},
{
"type": "basic",
"from": {
"key_code": "o",
"modifiers": {
"mandatory": [
"fn"
]
}
},
"to": [
{
"shell_command": "~/.config/karabiner/assets/complex_modifications/unicode_fn.sh.sh o"
}
],
"to_delayed_action": {
"to_if_invoked": [
{
"key_code": "v",
"modifiers": "command"
},
{
"shell_command": "~/.config/karabiner/assets/complex_modifications/restore_pb.sh"
}
],
"to_if_canceled": [
{
"key_code": "v",
"modifiers": "command"
},
{
"shell_command": "~/.config/karabiner/assets/complex_modifications/restore_pb.sh"
}
]
},
"parameters": {
"basic.to_delayed_action_delay_milliseconds": 100
}
},
{
"type": "basic",
"from": {
"key_code": "p",
"modifiers": {
"mandatory": [
"fn"
]
}
},
"to": [
{
"shell_command": "~/.config/karabiner/assets/complex_modifications/unicode_fn.sh.sh p"
}
],
"to_delayed_action": {
"to_if_invoked": [
{
"key_code": "v",
"modifiers": "command"
},
{
"shell_command": "~/.config/karabiner/assets/complex_modifications/restore_pb.sh"
}
],
"to_if_canceled": [
{
"key_code": "v",
"modifiers": "command"
},
{
"shell_command": "~/.config/karabiner/assets/complex_modifications/restore_pb.sh"
}
]
},
"parameters": {
"basic.to_delayed_action_delay_milliseconds": 100
}
},
{
"type": "basic",
"from": {
"key_code": "q",
"modifiers": {
"mandatory": [
"fn"
]
}
},
"to": [
{
"shell_command": "~/.config/karabiner/assets/complex_modifications/unicode_fn.sh.sh q"
}
],
"to_delayed_action": {
"to_if_invoked": [
{
"key_code": "v",
"modifiers": "command"
},
{
"shell_command": "~/.config/karabiner/assets/complex_modifications/restore_pb.sh"
}
],
"to_if_canceled": [
{
"key_code": "v",
"modifiers": "command"
},
{
"shell_command": "~/.config/karabiner/assets/complex_modifications/restore_pb.sh"
}
]
},
"parameters": {
"basic.to_delayed_action_delay_milliseconds": 100
}
},
{
"type": "basic",
"from": {
"key_code": "r",
"modifiers": {
"mandatory": [
"fn"
]
}
},
"to": [
{
"shell_command": "~/.config/karabiner/assets/complex_modifications/unicode_fn.sh.sh r"
}
],
"to_delayed_action": {
"to_if_invoked": [
{
"key_code": "v",
"modifiers": "command"
},
{
"shell_command": "~/.config/karabiner/assets/complex_modifications/restore_pb.sh"
}
],
"to_if_canceled": [
{
"key_code": "v",
"modifiers": "command"
},
{
"shell_command": "~/.config/karabiner/assets/complex_modifications/restore_pb.sh"
}
]
},
"parameters": {
"basic.to_delayed_action_delay_milliseconds": 100
}
},
{
"type": "basic",
"from": {
"key_code": "s",
"modifiers": {
"mandatory": [
"fn"
]
}
},
"to": [
{
"shell_command": "~/.config/karabiner/assets/complex_modifications/unicode_fn.sh.sh s"
}
],
"to_delayed_action": {
"to_if_invoked": [
{
"key_code": "v",
"modifiers": "command"
},
{
"shell_command": "~/.config/karabiner/assets/complex_modifications/restore_pb.sh"
}
],
"to_if_canceled": [
{
"key_code": "v",
"modifiers": "command"
},
{
"shell_command": "~/.config/karabiner/assets/complex_modifications/restore_pb.sh"
}
]
},
"parameters": {
"basic.to_delayed_action_delay_milliseconds": 100
}
},
{
"type": "basic",
"from": {
"key_code": "t",
"modifiers": {
"mandatory": [
"fn"
]
}
},
"to": [
{
"shell_command": "~/.config/karabiner/assets/complex_modifications/unicode_fn.sh.sh t"
}
],
"to_delayed_action": {
"to_if_invoked": [
{
"key_code": "v",
"modifiers": "command"
},
{
"shell_command": "~/.config/karabiner/assets/complex_modifications/restore_pb.sh"
}
],
"to_if_canceled": [
{
"key_code": "v",
"modifiers": "command"
},
{
"shell_command": "~/.config/karabiner/assets/complex_modifications/restore_pb.sh"
}
]
},
"parameters": {
"basic.to_delayed_action_delay_milliseconds": 100
}
},
{
"type": "basic",
"from": {
"key_code": "u",
"modifiers": {
"mandatory": [
"fn"
]
}
},
"to": [
{
"shell_command": "~/.config/karabiner/assets/complex_modifications/unicode_fn.sh.sh u"
}
],
"to_delayed_action": {
"to_if_invoked": [
{
"key_code": "v",
"modifiers": "command"
},
{
"shell_command": "~/.config/karabiner/assets/complex_modifications/restore_pb.sh"
}
],
"to_if_canceled": [
{
"key_code": "v",
"modifiers": "command"
},
{
"shell_command": "~/.config/karabiner/assets/complex_modifications/restore_pb.sh"
}
]
},
"parameters": {
"basic.to_delayed_action_delay_milliseconds": 100
}
},
{
"type": "basic",
"from": {
"key_code": "v",
"modifiers": {
"mandatory": [
"fn"
]
}
},
"to": [
{
"shell_command": "~/.config/karabiner/assets/complex_modifications/unicode_fn.sh.sh v"
}
],
"to_delayed_action": {
"to_if_invoked": [
{
"key_code": "v",
"modifiers": "command"
},
{
"shell_command": "~/.config/karabiner/assets/complex_modifications/restore_pb.sh"
}
],
"to_if_canceled": [
{
"key_code": "v",
"modifiers": "command"
},
{
"shell_command": "~/.config/karabiner/assets/complex_modifications/restore_pb.sh"
}
]
},
"parameters": {
"basic.to_delayed_action_delay_milliseconds": 100
}
},
{
"type": "basic",
"from": {
"key_code": "w",
"modifiers": {
"mandatory": [
"fn"
]
}
},
"to": [
{
"shell_command": "~/.config/karabiner/assets/complex_modifications/unicode_fn.sh.sh w"
}
],
"to_delayed_action": {
"to_if_invoked": [
{
"key_code": "v",
"modifiers": "command"
},
{
"shell_command": "~/.config/karabiner/assets/complex_modifications/restore_pb.sh"
}
],
"to_if_canceled": [
{
"key_code": "v",
"modifiers": "command"
},
{
"shell_command": "~/.config/karabiner/assets/complex_modifications/restore_pb.sh"
}
]
},
"parameters": {
"basic.to_delayed_action_delay_milliseconds": 100
}
},
{
"type": "basic",
"from": {
"key_code": "x",
"modifiers": {
"mandatory": [
"fn"
]
}
},
"to": [
{
"shell_command": "~/.config/karabiner/assets/complex_modifications/unicode_fn.sh.sh x"
}
],
"to_delayed_action": {
"to_if_invoked": [
{
"key_code": "v",
"modifiers": "command"
},
{
"shell_command": "~/.config/karabiner/assets/complex_modifications/restore_pb.sh"
}
],
"to_if_canceled": [
{
"key_code": "v",
"modifiers": "command"
},
{
"shell_command": "~/.config/karabiner/assets/complex_modifications/restore_pb.sh"
}
]
},
"parameters": {
"basic.to_delayed_action_delay_milliseconds": 100
}
},
{
"type": "basic",
"from": {
"key_code": "y",
"modifiers": {
"mandatory": [
"fn"
]
}
},
"to": [
{
"shell_command": "~/.config/karabiner/assets/complex_modifications/unicode_fn.sh.sh y"
}
],
"to_delayed_action": {
"to_if_invoked": [
{
"key_code": "v",
"modifiers": "command"
},
{
"shell_command": "~/.config/karabiner/assets/complex_modifications/restore_pb.sh"
}
],
"to_if_canceled": [
{
"key_code": "v",
"modifiers": "command"
},
{
"shell_command": "~/.config/karabiner/assets/complex_modifications/restore_pb.sh"
}
]
},
"parameters": {
"basic.to_delayed_action_delay_milliseconds": 100
}
},
{
"type": "basic",
"from": {
"key_code": "z",
"modifiers": {
"mandatory": [
"fn"
]
}
},
"to": [
{
"shell_command": "~/.config/karabiner/assets/complex_modifications/unicode_fn.sh.sh z"
}
],
"to_delayed_action": {
"to_if_invoked": [
{
"key_code": "v",
"modifiers": "command"
},
{
"shell_command": "~/.config/karabiner/assets/complex_modifications/restore_pb.sh"
}
],
"to_if_canceled": [
{
"key_code": "v",
"modifiers": "command"
},
{
"shell_command": "~/.config/karabiner/assets/complex_modifications/restore_pb.sh"
}
]
},
"parameters": {
"basic.to_delayed_action_delay_milliseconds": 100
}
}
]
}
]
}
"""Generator script
usage: python unicode_fn.py > unicode_fn.json
"""
import json
import sys
keys = [chr(ord('a')+i) for i in range(26)]
activate_script = "~/.config/karabiner/assets/complex_modifications/unicode_fn.sh"
restore_script = "~/.config/karabiner/assets/complex_modifications/restore_pb.sh"
def make_rules():
restore = [
{"key_code": "v", "modifiers": "command"},
{"shell_command": restore_script},
]
manipulators = []
for key in keys:
manipulators.append({
"type": "basic",
"from": {
"key_code": key,
"modifiers": {
"mandatory": ["fn"],
}
},
"to": [
{"shell_command": activate_script + " " + key}
],
"to_delayed_action": {
"to_if_invoked": restore,
"to_if_canceled": restore,
},
"parameters": {
"basic.to_delayed_action_delay_milliseconds": 100
},
})
return {
"title": "Unicode letters",
"rules": [
{
"description": "Unicode letters with Fn",
"manipulators": manipulators,
}
]
}
if __name__ == "__main__":
json.dump(make_rules(), sys.stdout, indent=2)
#!/bin/zsh
# Copies unicode character to clipboard
# usage: unicode_fn.sh <key>
export LC_ALL='en_US.UTF-8'
export LANG='en_US.UTF-8'
# Customize character for each key below
# Can be unicode directly or unicode hex points, eg 1D70C
typeset -A unicode_characters=( a '𝛼' b '𝛽' c 'πœ’'
d '𝛿' e 'πœ€' f 'πœ™'
g '𝛾' h 'πœƒ' i 'πœ„'
j 'πœ–' k 'πœ…' l 'πœ†'
m 'πœ‡' n 'πœ‚' o '𝜊'
p 'πœ‹' q 'πœ“' r '𝜌'
s '𝜎' t '𝜏' u 'πœ“'
v '𝜈' w 'πœ”' x 'πœ’'
y 'πœ†' z '𝜁'
)
key="$1"
echo -n "$key " >> ~/kb_test
date >> ~/kb_test
# Copy current clipboard content to 'ruler' pboard
pbpaste | pbcopy -pboard ruler &&
printf "\\U${unicode_characters[${key:-a}]}" | pbcopy
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment