Skip to content

Instantly share code, notes, and snippets.

@GGORG0
Last active December 10, 2022 20:29
Show Gist options
  • Save GGORG0/9f99a148359674655a2f5351530464d3 to your computer and use it in GitHub Desktop.
Save GGORG0/9f99a148359674655a2f5351530464d3 to your computer and use it in GitHub Desktop.
flash keyboard lights
#!/usr/bin/env python
# -*- coding: utf-8 -*-
import time
import os
import sys
import glob
if os.name != "posix":
print("ERROR: Linux only!")
sys.exit(1)
if os.geteuid() != 0:
print("ERROR: Run this as root!")
sys.exit(1)
files = glob.glob("/sys/class/leds/*lock")
print("LEDs found:")
for i, led in enumerate(files):
print(f" - {i}: {os.path.basename(led)}")
file = open(os.path.join(files[int(input("Your choice: ").strip())], "brightness"), "w")
x = False
delay = float(input("Delay: ").strip())
try:
while True:
file.write("1" if x else "0")
file.flush()
time.sleep(delay)
x = not x
except KeyboardInterrupt:
print("Exiting...")
file.close()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment