Created
April 15, 2024 02:49
-
-
Save lamnguyenx/9d2e2c10c33749f486cf9a4c3943c13c to your computer and use it in GitHub Desktop.
macos autokey
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/bin/python3 | |
# save to .config/autokey/data/Macos | |
import copy | |
import json | |
Mappings = { | |
'<ctrl>+<insert>': '<super>+c', | |
'<shift>+<insert>': '<super>+c', | |
'<ctrl>+x': '<super>+x', | |
'<ctrl>+z': '<super>+z', | |
'<ctrl>+s': '<super>+s', | |
'<ctrl>+a': '<super>+a', | |
'<ctrl>+f': '<super>+f', | |
'<ctrl>+n': '<super>+n', | |
'<ctrl>+r': '<super>+r', | |
'<ctrl>+k': '<super>+k', | |
'<ctrl>+l': '<super>+l', | |
'<home>': '<super>+<left>', | |
'<end>': '<super>+<right>', | |
'<page_up>': '<super>+<up>', | |
'<page_down>': '<super>+<down>', | |
'<ctrl>+t': '<super>+t', | |
'<ctrl>+w': '<super>+w', | |
'<ctrl>+<shift>+t': '<super>+<shift>+t', | |
} | |
Json_Template = { | |
'type': 'script', | |
'description': r'TBD', | |
'store': {}, | |
'modes': [3], | |
'usageCount': 0, | |
'prompt': False, | |
'omitTrigger': False, | |
'showInTrayMenu': False, | |
'abbreviation': { | |
'abbreviations': [], | |
'backspace': True, | |
'ignoreCase': False, | |
'immediate': False, | |
'triggerInside': False, | |
'wordChars': '[\\w]' | |
}, | |
'hotkey': { | |
'modifiers': [r'TBD'], | |
'hotKey': r'TBD' | |
}, | |
'filter': { | |
'regex': None, | |
'isRecursive': False | |
} | |
} | |
for src, tgt in Mappings.items(): | |
name = src.replace('<','_').replace('>','_') | |
Json_Dict = copy.deepcopy(Json_Template) | |
Json_Dict['description'] = name | |
Json_Dict['hotkey']['modifiers'] = tgt.split('+')[:-1] | |
Json_Dict['hotkey']['hotKey'] = tgt.split('+')[-1] | |
f_json = f'.{name}.json' | |
with open(f_json, 'w+') as F: | |
F.write(json.dumps(Json_Dict, indent=4, ensure_ascii=False)) | |
f_python = f'{name}.py' | |
with open(f_python, 'w+') as F: | |
F.write(f'keyboard.send_keys("{src}")') |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment