Skip to content

Instantly share code, notes, and snippets.

@ubershmekel
Last active May 19, 2022 00:33
Show Gist options
  • Star 9 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save ubershmekel/6626111 to your computer and use it in GitHub Desktop.
Save ubershmekel/6626111 to your computer and use it in GitHub Desktop.
1-script install xfce4 hotkeys for chromebook ubuntu
"""
1-script install xfce4 hotkeys for chromebook ubuntu
You might need to `killall xfconfd` or restart xfce for these to take effect.
"""
import os
import datetime
addage = [
""" <property name="F9" type="string" value="volume down"/>\n""",
""" <property name="F10" type="string" value="volume up"/>\n""",
""" <property name="F6" type="string" value="brightness down"/>\n""",
""" <property name="F7" type="string" value="brightness up"/>\n""",
]
where_to_add = """<property name="XF86WWW" type="string" value="exo-open --launch WebBrowser"/>"""
xml_fn = '~/.config/xfce4/xfconf/xfce-perchannel-xml/xfce4-keyboard-shortcuts.xml'
fn = os.path.expanduser(xml_fn)
text = open(fn).read()
if addage[0].strip() in text:
print("Already added hotkeys, not modifying")
exit()
bu_fn = fn + '.bu.' + datetime.datetime.now().isoformat()
with open(bu_fn, 'w') as fhand:
fhand.write(text)
print('saved backup at %s' % bu_fn)
new_lines = []
for line in text.splitlines(True):
new_lines.append(line)
if where_to_add in line:
new_lines += addage
new_text = ''.join(new_lines)
with open(fn, 'w') as fhand:
fhand.write(new_text)
print('shortcut keys installed')
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment