Skip to content

Instantly share code, notes, and snippets.

@sl5net
Created November 7, 2020 13:22
Show Gist options
  • Save sl5net/ff5c8ead7ef7ac95fd9e3a100be6fa6c to your computer and use it in GitHub Desktop.
Save sl5net/ff5c8ead7ef7ac95fd9e3a100be6fa6c to your computer and use it in GitHub Desktop.
data["hotKey"]["hotKey"] = "<f11>" KeyError: 'hotKey'
from pathlib import Path
import json
home = str(Path.home())
path = home + "/.config/autokey/data/Sample Scripts/"
jsonFilePath = home + "/.config/autokey/data/Sample Scripts/.run-run-lintalistAHK-all.json"
# /home/administrator/.config/autokey/data/Sample Scripts/.run-run-lintalistAHK-all.json
# /home/administrator.config/autokey/data/Sample Scripts/.run-run-lintalistAHK-all.json'
# {
# "hotkey": {
# "modifiers": [],
# "hotKey": "<f12>"
# },
# }
with open(jsonFilePath) as f:
data = json.load(f)
data["hotKey"]["hotKey"] = "<f11>"
# In Python, strings are immutable, so you can't change their characters in-place.
with open(jsonFilePath, 'w') as f:
json.dump(data, f)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment