This answer was inspired by this answer to How to run a command or script at screen lock/unlock?
For Ubuntu 14.04:
Assuming your using the default network manager, create a script (I put mine in ~/bin and called it netlock.sh)
Here's the content:
#!/bin/bash
dbus-monitor --session "type='signal',interface='com.ubuntu.Upstart0_6'" | \
(
while true; do
read X
if echo $X | grep "desktop-lock" &> /dev/null; then
nmcli nm enable false;
elif echo $X | grep "desktop-unlock" &> /dev/null; then
nmcli nm enable true;
fi
done
)
This script will disable networking on lock and re-enable on unlock.
If you want it to run every time at startup see How to run scripts on start up?
If you want it to run everytime you login, see How do I start applications automatically on login?
For Ubuntu 16.04: simply edit the script and change the nmcli nm enable false
to nmcli networking off
and the nmcli nm enable true
to nmcli networking on
as required due to changes in nmcli
Of course anything already downloaded and buffered will still play until the buffers run dry so if you want more exact control you'll have to use the pause button on the youtube player.
I can't gaurantee that everything will resume where you left off, as a server can drop inactive connections, but hopefully this is close to what you want.
lsb_release -a
into your post. Thank you for helping us help you! – Elder Geek May 06 '17 at 22:05