Ported xcaffeine to bash, removed Python version

This commit is contained in:
2022-09-21 20:28:35 -04:00
parent 2045e92b06
commit e3de00534f
6 changed files with 28 additions and 37 deletions
+1 -1
View File
@@ -1,5 +1,5 @@
[Desktop Entry]
Exec=/usr/local/bin/xcaffeine.py
Exec=/usr/local/bin/xcaffeine.sh
Icon=
Name=xcaffeine
Path=
-32
View File
@@ -1,32 +0,0 @@
#!/usr/bin/env python3
# external modules
from os import setuid, system
from pwd import getpwnam
from subprocess import Popen, PIPE, STDOUT
from time import sleep
# depends on X11, libpulse (compatible w/Pipewire&PulseAudio)
# START USER CHANGEABLE VARIABLES
# list of pactl search terms
pactl_search = ['jellyfinmediaplayer', 'rpcs3']
# frequency to check for activity (in seconds)
timeout = 290
# FINISH USER CHANGEABLE VARIABLES
# ensure running as correct user
setuid(1000)
while True:
sleep(timeout)
for search_term in pactl_search:
command = f"pactl list | grep {search_term[:-1]}"
output = Popen(command, shell=True, stdin=PIPE, stdout=PIPE, stderr=STDOUT, close_fds=True)
block = output.communicate()[0].strip() # blocks the program from proceeding until stdout is given
if block.decode('utf-8').__contains__(search_term):
print(f"Whitelisted content ({search_term}) is active, keeping screen alive...")
system('xset s off -dpms')
sleep(5)
system('xset s on +dpms')
+23
View File
@@ -0,0 +1,23 @@
#!/usr/bin/env bash
# depends on X11, libpulse (compatible w/Pipewire&PulseAudio)
# START USER CHANGEABLE VARIABLES
# list of pactl search terms
pactl_search=('jellyfinmediaplayer' 'rpcs3')
# frequency to check for activity (in seconds)
timeout=290
# FINISH USER CHANGEABLE VARIABLES
while [ True ]; do
sleep $timeout
for term in ${pactl_search[@]}; do
search_result=$(pactl list | grep $term)
if [ ! -z "$search_result" ]; then
echo "Whitelisted content ($term) is active, keeping screen alive..."
xset s off -dpms
sleep 5
xset s on +dpms
fi
done
done