Prevent OS from going to sleep/standby when some media is playing

My problem: When Spotify is playing, the system goes into sleep/standby (not sure which one or if it’s the same) after 10 mins - which is what it says in my settings:

[Screenshot, 2021-01-02 02:51:26 - Paste.Pics](energy saving settings)
- and Spotify stops playing.
However, as long as some media is playing back , be it video or audio, in the browser or a media player, I’d of course like it to not do that. How can I tell the systems, it’s actually not idling when playing media and therefore shouldn’t go to sleep?

When I use Plex Media Player, I ditch my Pulseaudio and launch, then Pulseaudio comes back when I close Plex.

Perhaps this is an idea that can work - launch spotify with a script along the lines of:

IF Spotify is playing THEN pkill spotify && enable sleep
ELSE disable sleep && launch spotify.

systemctl status
I think you want the ‘inactive’ status (sleep and suspend) here checking sleep:

● - Sleep
Loaded: loaded (/usr/lib/systemd/system/; static)
Active: inactive (dead)
Docs: man:systemd.special(7)

There’s also Caffiene (I think for gnome, I used it before) With KDE (assuming you’re using a laptop and want power saving active) then you need to have the battery icon enabled, you can quickly toggle power settings there.

You can look at your System Tray settings - Battery and Brightness - and set up a keyboard shortcut to bring that up for an easy click. The trouble is that once it’s off, it won’t auto-click on… so I’d tend to bring that up and pin it - permanent reminder that you disabled the checkbox.

Finally - my chosen solution…


Why not create a new activity called ‘Caffiene’?
Then (under Energy Saving) you can look into separate Activity settings. Turn off the screen, but don’t suspend.
Now you just need to assign spotify to open in that activity.

Yes, that’s the one - love it. I use Activities quite a bit these days - 1. Main (Tiling with krohnkite)

    1. Floating windows screen for doing another task…
    1. Media activity that usually houses a music player, or Plex player (generally fullscreen or floating - but not tiling).

I don’t use power saving, if I play music I turn off the TV - the computer doesn’t sleep unless I put the keyboard away and hit sleep because it’s a desktop.

I can’t tell the computer to turn off the screen, because I use HDMI via a receiver - so turning off the screen also disables my audio.

I think Spotify away from power sources is best relegated to mobile devices - until we have true mobile laptops (ARM devices FTW).

1 Like

Was just looking for the answer to this myself, why does it even go to sleep when media is playing I mean it knows media is playing because it has a pop-up warning. How about instead of displaying a warning just don’t go to sleep?

Thx for the suggestions. All sounds like one hell of a lot of work and i wouldn’t know where to start, it would need to be done for all media players and media websites so its not just one “app” like plex.

Think i shall just stick with the PITA option of turning of the sleep in the settings when using media even though this function should be default (or at least a user option).

I simply disabled sleep - if I don’t hit a key, it won’t happen… I guess if I enabled sleep it’d be 3 hours or something so that it wouldn’t happen during Plex or Radio listening without much interaction.

I agree, Caffeine sucks - it should have a timer (i.e. 2 or 3 hours of Caffeine for a click, or media detection).

With KDE it is very simple to use an Activity, make a new one called Caffeine and make that have special power settings… in Settings/Activity Power Settings I did set one for ‘bedtime’ which puts mine to sleep after 2 hours so I could leave it running and doze off.

I haven’t tested it, I’m curious of I left a radio playing there and switched to using my main Activity… if I’m not in the ‘Caffeine’ activity will the settings hold whilst something’s running in there? I don’t know.

One thing I do love to do is to use scripts bound to mouse gestures.

Here’s my PLEX one…

So I draw a PLEX sign to launch the script.

Here’s the script:

systemctl --user stop pulseaudio.socket systemctl --user stop pulseaudio.service
sleep 5
systemctl --user start pulseaudio.service

The effect is that Pulse goes dead (i.e. volume control goes blank) and Plex uses Alsa and gets passthrough for Dolby to the receiver.

The pulseaudio.service doesn’t actually restart until AFTER Plex is killed.

You could do the same thing…


sudo systemctl mask

Launch Plex, then re-enable it:

sudo systemctl unmask

If it works for that, and you want to play a 2 hour youtube video, then you make a Youtube webapp and make a script for that.

Or just make a ‘sleep’ script which will toggle sleep and bind that to something that makes sense (maybe Alt+Pause) with a notification.

I do this with my Logi keyboard function setting and get a notification telling me if I turned them on or off:

checkstatus=$(solaar config 1 | tail -1 | awk '{ print $3 }')
echo "$checkstatus"
if [[ "$checkstatus" == "True" ]] ; then
        solaar config 1 fn-swap off && notify-send 'Functions OFF'
        solaar config 1 fn-swap on && notify-send 'Functions ON'

It’s worth figuring out, because it gives you some power. Track it down - KDE config is all in text files.

In KDE tick the Presentation Mode box and it prevents sleep globally I think.
Click the Screen Configuration icon in tray, and tick the box.

Wow, that’s cool.
Is there a way to enable that with a command?
e.g. a bash script…

  1. enable presentation mode
  2. launch plex
    Hmmm though unlike pulse it might be harder to get presentation mode to cancel after closing plex.

I’m pretty sure a command exists to switch that ON/OFF. Too lazy to find it though :smiley:

# To set presentation mode
inhibit_cookie=$(qdbus org.freedesktop.PowerManagement.Inhibit /org/freedesktop/PowerManagement/Inhibit org.freedesktop.PowerManagement.Inhibit.Inhibit "a name" "a reason")

# To unset presentation mode
qdbus org.freedesktop.PowerManagement.Inhibit /org/freedesktop/PowerManagement/Inhibit org.freedesktop.PowerManagement.Inhibit.UnInhibit $inhibit_cookie

Actually I ran into quite a few threads with no decent solutions…
People have long complained that KDE doesn’t bother detecting if audio is playing (allow dim screen but no sleep) or video (disable sleep and screensaving) and only detects mouse/keyboard activity.

I think it is up to the application to have a proper implementation of such behavior, here are examples with some applications:


It says that “application XXX is using Presentation mode, doing ZZZ action” (and preventing system sleep).

1 Like

Haha yes, I just pinned the widget open and tested this with Plex - same result. So it shouldn’t sleep or dim the display at all.

The time I had an issue last was doing a quick reinstall and restoring a Timeshift snapshot some 3 months ago, I forgot to disable power saving so the screen locked during Timeshift parsing it’s lists and ended up having fun getting back to the desktop and disabling it before the timeshift had finished…

It may be off topic but I remember that on my first Manjaro installation, it was shutting the screen down after 10 minutes of ‘inactivity’ when watching Youtube video, and I troubleshoot it by setting 15 minutes before screen shutdown in KDE, but it was still shutting down the screen at 10 minutes, and I think I had an issue with non KDE specific settings that I had to change, if I recall correctly I think this was related to this Display Power Management Signaling - ArchWiki but I can’t login to my account on the archived forum so I can’t check if I marked a thread related to that to confirm. It was after an update I think that I started noticing that screen was shutting down while watching long Youtube videos. Maybe the KDE settings are OK but something overrides it?

//EDIT: I may have used xset s off or xset s off -dpms