title: How to avoid suspending while music is playing
body: <p>I have a simple problem: I would like my computer to avoid suspending when music or another media is playing on a desktop application on my computer. I'm running <strong>Fedora Workstation 36</strong> with Gnome 42.2.</p>
  <p>This is my first time using GNU/Linux so I'm not very good at it.
  I did some research and was able to create a bash script with a command of pulseaudio/pipewire/WirePlumber:</p>
  <pre><code>#!/bin/bash
  
  command=$(pactl list sinks)
  state='RUNNING'
  
  if [[ &quot;$command&quot; == *&quot;$state&quot;* ]]; then
      echo &quot;Media playing detected&quot;
      gsettings set org.gnome.settings-daemon.plugins.power sleep-inactive-ac-type 'nothing'
      echo 'Set suspend status OFF'
  #   sleep 10s
  
  else
      echo &quot;Media playing no detected&quot;
      gsettings set org.gnome.settings-daemon.plugins.power sleep-inactive-ac-type 'suspend'
      echo 'Set suspend status ON'
      time_suspend_sec=$(gsettings get org.gnome.settings-daemon.plugins.power sleep-inactive-ac-timeout)
      let time_suspend_min=time_suspend_sec/60
      echo 'Automatic suspend when idle' $time_suspend_min 'min'
  #   sleep 10s
  fi
  </code></pre>
  <p>The script works fine when I run it manually from the console, but I'm trying to get it to run automatically when I pause or resume playback.
  Maybe there is a WirePlumber API that sends a signal every time the playback state changes between play and pause, but I haven't found it. I also thought to get this signal from the notification but I don't know how to do it.</p>
  <p>Another option would be to infinitely execute the script every second but I don't know if this is possible.</p>
  <p>Caffeine or Espresso Gnome extensions aren't an option because they do not detect when a song is playing or paused, only when an application is running.</p>
  <p>My desired behaviour is beneficial for several reasons:</p>
  <ul>
  <li>If the user leaves a music application open in the background, but with playback halted, the computer will not stay awake indefinitely.</li>
  <li>If the user leaves the computer with music playing, intending the music to carry on, they need not worry about having their music player in fullscreen to keep the music going.</li>
  <li>The user can take advantage of this behaviour in different ways. For example, they could select 20 minutes of relaxing music before bed. When the 20 minute playlist ends, the computer will then suspend for the night. The sleep duration thus automatically adjusts to the length of the playlist.</li>
  </ul>