Using Mate on GhostBSD, one frustration I've had is that the screen keeps locking/blanking while I'm watching a video or playing audio. This is especially true in Firefox, where even a YouTube video wouldn't inhibit the screen idle. So I whipped up this script to detect when media is being played, and if so, use mate-session-inhibit to prevent the screen from blanking. Hopefully others find it useful.
#!/bin/sh
# Function to inhibit the session
inhibit_session() {
uninhibit_session
mate-session-inhibit --inhibit 'idle:suspend' sleep 5h &
INHIBIT_PID=$!
}
# Function to un-inhibit the session
uninhibit_session() {
if [ -n "$INHIBIT_PID" ]; then
kill $INHIBIT_PID
INHIBIT_PID=""
fi
}
# Monitor D-Bus for media playback events
dbus-monitor "path=/org/mpris/MediaPlayer2" "interface=org.mpris.MediaPlayer2.Player" | while read -r line; do
if echo "$line" | grep -e "Playing" -e "member=Seeked"; then
echo "Media is playing. Inhibiting session..."
inhibit_session
elif echo "$line" | grep -q "Paused"; then
echo "Media is not playing. Uninhibiting session..."
uninhibit_session
elif echo "$line" | grep -q "Stopped"; then
echo "Media is not playing. Uninhibiting session..."
uninhibit_session
fi
done```