Open komoricodrutz opened 19 hours ago
Ha! Works also with mplayer and a video file of your choice... If you wish to also play sound, you can remove the "-nosound" entry in the initialisation string. If you wish to set the volume, replace the "-nosound" option with "-volume xx" (in percent) to the initialisation string. For example, "-volume 40" worked fine to have my selected video at a non-disturbing audio level. Depending on your specific file, this value may differ, so you should experiment with that value a bit. You can most definitely experiment with the playlist option of mplayer.
LE: I have noticed that mplayer causes the idle time to reset randomly. Currently researching a way around it or using a different player
Example with sound at 30%: playrinitstrg="-volume 30 -fs -loop 0 -vo gl"
#!/bin/bash
# Variables to be modified if needed
#1: Time in seconds. Change as needed. As xprintidle works with milliseconds, this makes it easier for you to set the timeout value in seconds instead.
waitsec=3
#2: Enter your player launch command here
player="mplayer"
#3: Enter the command-line initialisation string for the player
playrinitstrg="-nosound -fs -loop 0 -fixed-vo -vo gl"
#4: If you are not using a web app, comment out the playrprofpath entry here.
# If you are, then enter the profile path to that web app:
# (for some reason, using "~" doesn't work from this script and I am too lazy to investigate why.
# That's why the full profile path needs to be specified)
# Left-over from the initial browser version. Not needed in this context.
#playrprofpath="/home/[your-user-id]/.local/share/ice/firefox/TestScr8396"
#5: Enter the path of the file or playlist you wish to display:
playrurl="/[path]/[to]/[video.mp4]"
# Variables which MIGHT need modifying
#1: If you are NOT using a web app, where a dedicated profile is needed, delete the $playrprofpath variable from here:
playrtart="$player $playrinitstrg $playrurl"
# These variables do not really need modifying
# Multiplier for milliseconds. DO NOT TOUCH! xprintidle works with milliseconds:
multiplix=1000
# Seconds converted to milliseconds:
waitms=$((waitsec * multiplix))
# User-friendly translation output of seconds to milliseconds
echo $waitsec Seconds translates to $waitms Milliseconds
# Resets the player ID variable for the initial run
player_id=""
# Start the loop
while true; do
# Sets the variable to how long X has been idle
idle=`xprintidle`
# If the idle time has been greater than the waiting time, then starts running the commandsL
if [ $idle -gt $waitms ]; then
# If there is NO player ID, then
if [ -z $player_id ]; then
# Start the player
$playrtart &
# Get the player process PID
player_id="$!"
# User-friendly notification
echo "Away, running screensaver (id:$player_id)"
# This sleep entry is necessary, as for some reason the wmctrlid variable below does not work if set to be run immediately:
sleep 3
# Get the wmctrl WID (window ID) for our player ID
wmctrlid="$(wmctrl -l -p | grep $player_id | cut -c1-10)"
# Set the player window to full-screen (left-over from the browser version. Not needed, as the initialisation string also has the full-screen entry:
# wmctrl -ir "$wmctrlid" -b toggle,fullscreen
fi
# If you moved the mouse, then xprintidle time has been reset to smaller than the wait time value, so the loop resets:
# If there IS a player ID, this means that the pseudo-screensaver is already running:
elif [ $player_id ]; then
# User-friendly message for shutting down the pseudo-screensaver:
echo "Welcome back, closing screensaver (id:$player_id)"
# Gracefully quit the player:
wmctrl -ic "$wmctrlid"
# Resets the player ID:
player_id=""
fi
# Waits for a second before finishing the current loop
sleep 1
# Finish current loop
done
Enjoy!
Sooooo, I tried various solutions, because it seems there is no option to have mplayer stop resetting the idle time. Tested it out with vlc, but vlc has the behaviour that it reloads the player window on loop (same behaviour as WITHOUT the "-fixed-vo" option for mplayer, but apparently with no solution available), so the PID changes and the script can no longer close the vlc window on user interaction.
I tried it with mpv and it seems to work fine, without resetting the idle interval.
You just need to add the "--stop-screensaver=no" option.
And also install mpv, of course.
Just as in the mplayer version, if you wish to hear the video sound, remove the "--no-audio" option or if you wish to hear audio, but at a specific volume, replace the "--no-audio" option with "--volume=xx", where "xx" stands for the audio volume percentage. Again, experiment with various percentage settings.
As above, for me the value 40 worked fine:
playrinitstrg="--stop-screensaver=no --fs --volume=40 --loop"
Here is the full script:
#!/bin/bash
# Variables to be modified if needed
#1: Time in seconds. Change as needed. As xprintidle works with milliseconds, this makes it easier for you to set the timeout value in seconds instead.
waitsec=3
#2: Enter your player launch command here
player="mpv"
#3: Enter the command-line initialisation string for the player
playrinitstrg="--stop-screensaver=no --fs --no-audio --loop"
#4: If you are not using a web app, comment out the playrprofpath entry here.
# If you are, then enter the profile path to that web app:
# (for some reason, using "~" doesn't work from this script and I am too lazy to investigate why.
# That's why the full profile path needs to be specified)
# Left-over from the initial browser version. Not needed in this context.
#playrprofpath="/home/[your-user-id]/.local/share/ice/firefox/TestScr8396"
#5: Enter the path of the file or playlist you wish to display:
playrurl="/[path]/[to]/[video.mp4]"
# Variables which MIGHT need modifying
#1: If you are NOT using a web app, where a dedicated profile is needed, delete the $playrprofpath variable from here:
playrtart="$player $playrinitstrg $playrurl"
# These variables do not really need modifying
# Multiplier for milliseconds. DO NOT TOUCH! xprintidle works with milliseconds:
multiplix=1000
# Seconds converted to milliseconds:
waitms=$((waitsec * multiplix))
# User-friendly translation output of seconds to milliseconds
echo $waitsec Seconds translates to $waitms Milliseconds
# Resets the player ID variable for the initial run
player_id=""
# Start the loop
while true; do
# Sets the variable to how long X has been idle
idle=`xprintidle`
# If the idle time has been greater than the waiting time, then starts running the commandsL
if [ $idle -gt $waitms ]; then
# If there is NO player ID, then
if [ -z $player_id ]; then
# Start the player
$playrtart &
# Get the player process PID
player_id="$!"
# User-friendly notification
echo "Away, running screensaver (id:$player_id)"
# This sleep entry is necessary, as for some reason the wmctrlid variable below does not work if set to be run immediately:
sleep 3
# Get the wmctrl WID (window ID) for our player ID
wmctrlid="$(wmctrl -l -p | grep $player_id | cut -c1-10)"
# Set the player window to full-screen (left-over from the browser version. Not needed, as the initialisation string also has the full-screen entry:
# wmctrl -ir "$wmctrlid" -b toggle,fullscreen
fi
# If you moved the mouse, then xprintidle time has been reset to smaller than the wait time value, so the loop resets:
# If there IS a player ID, this means that the pseudo-screensaver is already running:
elif [ $player_id ]; then
# User-friendly message for shutting down the pseudo-screensaver:
echo "Welcome back, closing screensaver (id:$player_id)"
# Gracefully quit the player:
wmctrl -ic "$wmctrlid"
# Resets the player ID:
player_id=""
fi
# Waits for a second before finishing the current loop
sleep 1
# Finish current loop
done
Enjoy!
Here is the script I adapted, which allows you to use any different browser and also an ICE or progressive Web App (I'm using Linux Mint and a dedicated Web App so as not to interfere with normal browser operations). It also uses wmctrl instead of kill, because it gracefully quits the browser, thus avoiding those session restore interactive popups if the browser has been quit ungracefully for too many times. So you'll also have to install wmctrl besides xprintidle. I've also added comments with what each command does.
Enjoy!