Created
March 8, 2019 12:04
-
-
Save doyousketch2/37ec73fa32114b7dea68a255350daeba to your computer and use it in GitHub Desktop.
color your LXDE taskbar on the weekend
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/env python3 | |
# -*- coding: utf-8 -*- | |
##========================================================= | |
## taskbar_tint.py Mar 2019 | |
## | |
## Eli Innis @Doyousketch2 Doyousketch2 @ yahoo.com | |
## | |
## GNU GPLv3 gnu.org/licenses/gpl-3.0.html | |
""" libs ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~""" | |
import os | |
import sys ## to retrieve args | |
import subprocess as sp ## commandline processes | |
""" vars ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~""" | |
# ┌───────────── minute (0 - 59) | |
# │ ┌───────────── hour (0 - 23) | |
# │ │ ┌───────────── day of the month (1 - 31) | |
# │ │ │ ┌───────────── month (1 - 12) | |
# │ │ │ │ ┌───────────── day of the week (0 - 6) (Sunday to Saturday; | |
# │ │ │ │ │ 7 is also Sunday on some systems) | |
# │ │ │ │ │ | |
# │ │ │ │ │ | |
# * * * * * command to execute | |
''' | |
crontab -e | |
# 4 am Mon | |
0 4 * * 1 ~/.config/lxpanel/taskbar_tint.py weekday | |
# 4 pm Fri | |
0 16 * * 5 ~/.config/lxpanel/taskbar_tint.py weekend | |
''' | |
configdir = '~/.config/lxpanel/LXDE/panels/' | |
temp = configdir +'temp' | |
panel = configdir +'panel' | |
bak = panel +'.bak' | |
weekDay_color = '#3465a4' | |
weekEnd_color = '#75507b' | |
arg = '' | |
if len( sys .argv ) > 1: | |
arg = sys .argv[1] | |
## https://stackoverflow.com/questions/55030437/how-can-i-change-one-line-in-text-file-with-python | |
## I feel like this can all be written to temp text, then output the entire contents in one go. | |
## I've done it before, but so tired right now, not looking up the specifics. | |
with open( panel, 'r' ) as data, open( temp, 'w' ) as tmp: | |
for line in data: | |
if line .startswith( ' tintcolor' ): | |
if arg == 'weekend': | |
tmp .write( ' tintcolor=' +weekEnd_color ) | |
else: | |
tmp .write( ' tintcolor=' +weekDay_color ) | |
else: | |
tmp .write( line ) | |
if os .path .isfile( bak ): | |
os .remove( bak ) | |
os .rename( panel, bak ) | |
os .rename( temp, panel ) | |
sp .run( ['lxpanelctl', 'restart'] ) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment