Code: Select all
#!/bin/bash
# put this script into /usr/bin/systemd/system-sleep/ or /usr/lib/systemd/system-sleep/
# owned by root and executable
if [ "${1}" == "pre" ]; then
/usr/bin/touch /tmp/got_suspended.txt
elif [ "${1}" == "post" ]; then
echo 1 > /sys/bus/pci/devices/0000:00:1f.3/remove
echo 1 > /sys/bus/pci/rescan
/usr/bin/touch /tmp/got_resumed.txt
fi
I therefore tried to automate a 'zoom kill', using the same run-on-suspend mechanism.
I've probably gone the long way round in trying to do this. However, I've written a short python program that uses wmctrl to list the open windows, and xdotool to kill one of them (I couldn't figure out how to use bash to do this, wmctrl won't kill windows, and I couldn't figure out how xdotool lists windows). When run by itself, the program works fine, killing any window with the string 'zoom' in the window title.
Code: Select all
with open(r'/tmp/abc123.txt', 'wt') as fout:
fout.write('got into program\n')
import subprocess as sp
# list all the windows
# wmctrl returns bytes, lines separated by \n
# the first 10 character positions in each line are the window number
# the window title appears later in the string
result = sp.run(['wmctrl', '-l'], capture_output=True)
output = result.stdout.decode()
lines = output.split('\n')
for line in lines:
if line.strip():
if 'zoom' in line.lower():
sp.run(['xdotool', 'windowkill', line[:10]])
OK, the beginner question - as it appears the python program doesn't run, presumably the system sends an error message somewhere. How do I access the error message? How do I debug this failure?
Perhaps more complicated questions - is there a better way to do what I'm trying to do? Or can you suggest why my attempt this way isn't working?