Skip to content

Instantly share code, notes, and snippets.

@matt-fff
Created October 19, 2018 16:23
Show Gist options
  • Save matt-fff/61b2224908c0b8c890e71abf2c958a15 to your computer and use it in GitHub Desktop.
Save matt-fff/61b2224908c0b8c890e71abf2c958a15 to your computer and use it in GitHub Desktop.
conky configuration (.desktop files in ~/.config/autostart/)
[Desktop Entry]
Exec=~/Workspaces/monitor_change.py
Name=Conky Automatic Restart
Comment=Run Conky automatic restart on monitor change
Type=Application
Icon=video-joined-displays-symbolic
NoDisplay=true
[Desktop Entry]
Exec=conky
Name=Conky System Monitor
Comment=Run Conky system monitor
Type=Application
Icon=conky-manager
NoDisplay=true
#!/usr/bin/env python3
import subprocess
import time
def get(cmd): return subprocess.check_output(cmd).decode("utf-8")
def count_screens(xr): return xr.count(" connected ")
# first count
xr1 = None
while True:
time.sleep(5)
# second count
xr2 = count_screens(get(["xrandr"]))
# check if there is a change in the screen state
if xr2 != xr1:
subprocess.Popen(["/usr/bin/pkill", "-f", "conky"])
time.sleep(5)
subprocess.Popen(["/usr/bin/conky"])
# set the second count as initial state for the next loop
xr1 = xr2
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment