Prevent Mint from suspending while playing music in Spotify

The name of the pictureThe name of the pictureThe name of the pictureClash Royale CLAN TAG#URR8PPP











up vote
2
down vote

favorite












In Linux Mint 17 I have Suspend when inactive for under Power Management set to 10 minutes.



The problem is that the system suspends even when I'm listening to music using Spotify.



Is there any way to prevent this?










share|improve this question





















  • This solution looks relevant, but the links in the solution are dead at time of writing.
    – LondonRob
    Mar 22 '16 at 19:43














up vote
2
down vote

favorite












In Linux Mint 17 I have Suspend when inactive for under Power Management set to 10 minutes.



The problem is that the system suspends even when I'm listening to music using Spotify.



Is there any way to prevent this?










share|improve this question





















  • This solution looks relevant, but the links in the solution are dead at time of writing.
    – LondonRob
    Mar 22 '16 at 19:43












up vote
2
down vote

favorite









up vote
2
down vote

favorite











In Linux Mint 17 I have Suspend when inactive for under Power Management set to 10 minutes.



The problem is that the system suspends even when I'm listening to music using Spotify.



Is there any way to prevent this?










share|improve this question













In Linux Mint 17 I have Suspend when inactive for under Power Management set to 10 minutes.



The problem is that the system suspends even when I'm listening to music using Spotify.



Is there any way to prevent this?







linux-mint power-management






share|improve this question













share|improve this question











share|improve this question




share|improve this question










asked Oct 4 '14 at 17:25









LondonRob

14710




14710











  • This solution looks relevant, but the links in the solution are dead at time of writing.
    – LondonRob
    Mar 22 '16 at 19:43
















  • This solution looks relevant, but the links in the solution are dead at time of writing.
    – LondonRob
    Mar 22 '16 at 19:43















This solution looks relevant, but the links in the solution are dead at time of writing.
– LondonRob
Mar 22 '16 at 19:43




This solution looks relevant, but the links in the solution are dead at time of writing.
– LondonRob
Mar 22 '16 at 19:43










2 Answers
2






active

oldest

votes

















up vote
4
down vote



accepted










I found this article which suggests a couple of ways to stop the screensaver from activating. I have not tested this but since they presumably issue events to stop the activation (the second does at least), that should also count as activity for the inactivity monitor. You'll have to test this though, I'm not sure it will work.




  1. Install caffeine. This can be done by adding a ppa to your system and then installing it like any other package. As long as you're using the normal Mint, this should also work for you.



    sudo add-apt-repository ppa:caffeine-developers/ppa
    sudo apt-get update
    sudo apt-get install caffeine


    Then, launch caffeine and its icon should appear in your system tray. You can choose which programs should cancel suspending.



    Note: As of the 2.7 release of caffeine, the program no longer has a GUI and works only as a daemon. When running, it will prevent the screensaver from activating so long as the active window is full screen.




  2. The LightsOn script. It won't check spotify by default but it is easy enough to modify it to do so. Just add spotify to the delay_progs array at the beginging of the script:



    delay_progs=("spotify")


    Then, add the script to your startup programs so it runs in the background. and it should stop you from suspending if spotify is running. Note that this does not check whether any music is playing, just whether the program is running.



Let me know if these don't work for the suspension and I'll try and hack something together using xdotool or similar programs.






share|improve this answer






















  • I've used caffeine and it's worked alright in the past. It seems buggy though since I've had it active and the screensaver would still kick in. Haven't debugged it further, though.
    – slm♦
    Oct 5 '14 at 15:29










  • @slm I haven't so I can't speak as to how well it works. The second solution, the shell script, looks very interesting. It's relatively straightforward and should be easy to expand to blocking suspension.
    – terdon♦
    Oct 5 '14 at 15:33










  • yeah I was just giving a recounting of my experience. 2nd solution is prob. A better approach to try.
    – slm♦
    Oct 5 '14 at 15:35











  • The script looks pretty good. Could you add a line to your answer showing how to run the script at start-up?
    – LondonRob
    Oct 6 '14 at 22:25










  • @LondonRob that depends on your desktop environment but for most it's something along the lines of settings => startup programs. That's where you can find it on Cinnamon for example. Alternatively, copy the caffeine.desktop file from /usr/share/applications to ~/.config/autostart/.
    – terdon♦
    Oct 6 '14 at 22:39

















up vote
0
down vote













I just posted an answer for a similar question:
Linux Mint: How to Avoid Suspending While Music is Playing



I have written a script to set the suspend timeout to "Never" while pactl detects a running audio source, then reverts the setting when no audio sources are detected.



Here is a copy of the latest answer and script:



I have done a little more work on the above script and it should now work in Cinnamon, Mate and Ubuntu running Gnome. I have tried it out on Live USB versions of Linux Mint 19 Cinnamon and Mate as well as Ubuntu 18.04 - Gnome.



#!/bin/sh

# Audiocaffeine

# Works in Linux Mint 19 - Cinnamon, Linux Mint 19 - Mate, Ubuntu 18.04 - Gnome

# Script to temporarily set suspend timout for AC and battery to "Never"
# while audio is playing. It then reverts the settings when audio is no longer detected.

# Determine if a valid desktop environment is running and exit if it doesn't.
echo "Reported desktop environment: ""$XDG_CURRENT_DESKTOP"
if [ "$XDG_CURRENT_DESKTOP" = "X-Cinnamon" ]; then
actimeoutid="org.cinnamon.settings-daemon.plugins.power sleep-inactive-ac-timeout"
batttimeoutid="org.cinnamon.settings-daemon.plugins.power sleep-inactive-battery-timeout"
disablevalue=0
elif [ "$XDG_CURRENT_DESKTOP" = "MATE" ]; then
actimeoutid="org.mate.power-manager sleep-computer-ac"
batttimeoutid="org.mate.power-manager sleep-computer-battery"
disablevalue=0
elif [ "$XDG_CURRENT_DESKTOP" = "ubuntu:GNOME" ]; then
actimeoutid="org.gnome.settings-daemon.plugins.power sleep-inactive-ac-type"
batttimeoutid="org.gnome.settings-daemon.plugins.power sleep-inactive-battery-type"
disablevalue="nothing"
else
echo "No valid desktop environment is running"
exit 1
fi

# Create .config directory to store settings if it doesn't exist.
if [ ! -d ~/.config ]; then
echo ".config directory not found!"
echo "Creating ~/.config"
mkdir ~/.config
fi

# Create audiocaffeine directory to store settings if it doesn't exist.
if [ ! -d ~/.config/audiocaffeine ]; then
echo "Configuration directory not found!"
echo "Creating ~/.config/audiocaffeine"
mkdir ~/.config/audiocaffeine
fi

# Restore previous value for AC suspend timeout if script
# was interrupted.
if [ -f ~/.config/audiocaffeine/acsuspend ]; then
echo "Restoring previous AC suspend timeout."
read acsuspendtime < ~/.config/audiocaffeine/acsuspend
gsettings set $actimeoutid $acsuspendtime
echo "Removing temporary file ~/.config/audiocaffeine/acsuspend"
rm ~/.config/audiocaffeine/acsuspend
fi

# Restore previous value for battery suspend timeout if script
# was interrupted.
if [ -f ~/.config/audiocaffeine/battsuspend ]; then
echo "Restoring previous battery suspend timeout."
read battsuspendtime < ~/.config/audiocaffeine/battsuspend
gsettings set $batttimeoutid $battsuspendtime
echo "Removing temporary file ~/.config/audiocaffeine/battsuspend"
rm ~/.config/audiocaffeine/battsuspend
fi

# Start main loop to check if audio is playing

while true; do

# Use pactl to detect if there are any running audio sources.
if pactl list | grep -q "State: RUNNING"; then

echo "Audio detected."

# If AC timeout was not previously saved, then save it.
if [ ! -f ~/.config/audiocaffeine/acsuspend ]; then
echo "Saving current AC suspend timeout."
gsettings get $actimeoutid > ~/.config/audiocaffeine/acsuspend
fi

# If battery timeout was not previously saved, then save it.
if [ ! -f ~/.config/audiocaffeine/battsuspend ]; then
echo "Saving current battery suspend timeout."
gsettings get $batttimeoutid > ~/.config/audiocaffeine/battsuspend
fi

# Set the suspend timouts to Never using gsettings.
echo "Changing suspend timeouts."
gsettings set $actimeoutid $disablevalue
gsettings set $batttimeoutid $disablevalue

else
echo "No audio detected."

# Restore previous value for AC suspend timeout and delete the
# temporary file storing it.
if [ -f ~/.config/audiocaffeine/acsuspend ]; then
echo "Restoring previous AC suspend timeout."
read acsuspendtime < ~/.config/audiocaffeine/acsuspend
gsettings set $actimeoutid $acsuspendtime
echo "Removing temporary file ~/.config/audiocaffeine/acsuspend"
rm ~/.config/audiocaffeine/acsuspend
fi

# Restore previous value for battery suspend timeout and delete the
# temporary file storing it.
if [ -f ~/.config/audiocaffeine/battsuspend ]; then
echo "Restoring previous battery suspend timeout."
read battsuspendtime < ~/.config/audiocaffeine/battsuspend
gsettings set $batttimeoutid $battsuspendtime
echo "Removing temporary file ~/.config/audiocaffeine/battsuspend"
rm ~/.config/audiocaffeine/battsuspend
fi

fi

# Pause the script for 60 seconds before doing the loop again.
sleep 60s

done





share|improve this answer






















    Your Answer







    StackExchange.ready(function()
    var channelOptions =
    tags: "".split(" "),
    id: "106"
    ;
    initTagRenderer("".split(" "), "".split(" "), channelOptions);

    StackExchange.using("externalEditor", function()
    // Have to fire editor after snippets, if snippets enabled
    if (StackExchange.settings.snippets.snippetsEnabled)
    StackExchange.using("snippets", function()
    createEditor();
    );

    else
    createEditor();

    );

    function createEditor()
    StackExchange.prepareEditor(
    heartbeatType: 'answer',
    convertImagesToLinks: false,
    noModals: false,
    showLowRepImageUploadWarning: true,
    reputationToPostImages: null,
    bindNavPrevention: true,
    postfix: "",
    onDemand: true,
    discardSelector: ".discard-answer"
    ,immediatelyShowMarkdownHelp:true
    );



    );













     

    draft saved


    draft discarded


















    StackExchange.ready(
    function ()
    StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2funix.stackexchange.com%2fquestions%2f159286%2fprevent-mint-from-suspending-while-playing-music-in-spotify%23new-answer', 'question_page');

    );

    Post as a guest






























    2 Answers
    2






    active

    oldest

    votes








    2 Answers
    2






    active

    oldest

    votes









    active

    oldest

    votes






    active

    oldest

    votes








    up vote
    4
    down vote



    accepted










    I found this article which suggests a couple of ways to stop the screensaver from activating. I have not tested this but since they presumably issue events to stop the activation (the second does at least), that should also count as activity for the inactivity monitor. You'll have to test this though, I'm not sure it will work.




    1. Install caffeine. This can be done by adding a ppa to your system and then installing it like any other package. As long as you're using the normal Mint, this should also work for you.



      sudo add-apt-repository ppa:caffeine-developers/ppa
      sudo apt-get update
      sudo apt-get install caffeine


      Then, launch caffeine and its icon should appear in your system tray. You can choose which programs should cancel suspending.



      Note: As of the 2.7 release of caffeine, the program no longer has a GUI and works only as a daemon. When running, it will prevent the screensaver from activating so long as the active window is full screen.




    2. The LightsOn script. It won't check spotify by default but it is easy enough to modify it to do so. Just add spotify to the delay_progs array at the beginging of the script:



      delay_progs=("spotify")


      Then, add the script to your startup programs so it runs in the background. and it should stop you from suspending if spotify is running. Note that this does not check whether any music is playing, just whether the program is running.



    Let me know if these don't work for the suspension and I'll try and hack something together using xdotool or similar programs.






    share|improve this answer






















    • I've used caffeine and it's worked alright in the past. It seems buggy though since I've had it active and the screensaver would still kick in. Haven't debugged it further, though.
      – slm♦
      Oct 5 '14 at 15:29










    • @slm I haven't so I can't speak as to how well it works. The second solution, the shell script, looks very interesting. It's relatively straightforward and should be easy to expand to blocking suspension.
      – terdon♦
      Oct 5 '14 at 15:33










    • yeah I was just giving a recounting of my experience. 2nd solution is prob. A better approach to try.
      – slm♦
      Oct 5 '14 at 15:35











    • The script looks pretty good. Could you add a line to your answer showing how to run the script at start-up?
      – LondonRob
      Oct 6 '14 at 22:25










    • @LondonRob that depends on your desktop environment but for most it's something along the lines of settings => startup programs. That's where you can find it on Cinnamon for example. Alternatively, copy the caffeine.desktop file from /usr/share/applications to ~/.config/autostart/.
      – terdon♦
      Oct 6 '14 at 22:39














    up vote
    4
    down vote



    accepted










    I found this article which suggests a couple of ways to stop the screensaver from activating. I have not tested this but since they presumably issue events to stop the activation (the second does at least), that should also count as activity for the inactivity monitor. You'll have to test this though, I'm not sure it will work.




    1. Install caffeine. This can be done by adding a ppa to your system and then installing it like any other package. As long as you're using the normal Mint, this should also work for you.



      sudo add-apt-repository ppa:caffeine-developers/ppa
      sudo apt-get update
      sudo apt-get install caffeine


      Then, launch caffeine and its icon should appear in your system tray. You can choose which programs should cancel suspending.



      Note: As of the 2.7 release of caffeine, the program no longer has a GUI and works only as a daemon. When running, it will prevent the screensaver from activating so long as the active window is full screen.




    2. The LightsOn script. It won't check spotify by default but it is easy enough to modify it to do so. Just add spotify to the delay_progs array at the beginging of the script:



      delay_progs=("spotify")


      Then, add the script to your startup programs so it runs in the background. and it should stop you from suspending if spotify is running. Note that this does not check whether any music is playing, just whether the program is running.



    Let me know if these don't work for the suspension and I'll try and hack something together using xdotool or similar programs.






    share|improve this answer






















    • I've used caffeine and it's worked alright in the past. It seems buggy though since I've had it active and the screensaver would still kick in. Haven't debugged it further, though.
      – slm♦
      Oct 5 '14 at 15:29










    • @slm I haven't so I can't speak as to how well it works. The second solution, the shell script, looks very interesting. It's relatively straightforward and should be easy to expand to blocking suspension.
      – terdon♦
      Oct 5 '14 at 15:33










    • yeah I was just giving a recounting of my experience. 2nd solution is prob. A better approach to try.
      – slm♦
      Oct 5 '14 at 15:35











    • The script looks pretty good. Could you add a line to your answer showing how to run the script at start-up?
      – LondonRob
      Oct 6 '14 at 22:25










    • @LondonRob that depends on your desktop environment but for most it's something along the lines of settings => startup programs. That's where you can find it on Cinnamon for example. Alternatively, copy the caffeine.desktop file from /usr/share/applications to ~/.config/autostart/.
      – terdon♦
      Oct 6 '14 at 22:39












    up vote
    4
    down vote



    accepted







    up vote
    4
    down vote



    accepted






    I found this article which suggests a couple of ways to stop the screensaver from activating. I have not tested this but since they presumably issue events to stop the activation (the second does at least), that should also count as activity for the inactivity monitor. You'll have to test this though, I'm not sure it will work.




    1. Install caffeine. This can be done by adding a ppa to your system and then installing it like any other package. As long as you're using the normal Mint, this should also work for you.



      sudo add-apt-repository ppa:caffeine-developers/ppa
      sudo apt-get update
      sudo apt-get install caffeine


      Then, launch caffeine and its icon should appear in your system tray. You can choose which programs should cancel suspending.



      Note: As of the 2.7 release of caffeine, the program no longer has a GUI and works only as a daemon. When running, it will prevent the screensaver from activating so long as the active window is full screen.




    2. The LightsOn script. It won't check spotify by default but it is easy enough to modify it to do so. Just add spotify to the delay_progs array at the beginging of the script:



      delay_progs=("spotify")


      Then, add the script to your startup programs so it runs in the background. and it should stop you from suspending if spotify is running. Note that this does not check whether any music is playing, just whether the program is running.



    Let me know if these don't work for the suspension and I'll try and hack something together using xdotool or similar programs.






    share|improve this answer














    I found this article which suggests a couple of ways to stop the screensaver from activating. I have not tested this but since they presumably issue events to stop the activation (the second does at least), that should also count as activity for the inactivity monitor. You'll have to test this though, I'm not sure it will work.




    1. Install caffeine. This can be done by adding a ppa to your system and then installing it like any other package. As long as you're using the normal Mint, this should also work for you.



      sudo add-apt-repository ppa:caffeine-developers/ppa
      sudo apt-get update
      sudo apt-get install caffeine


      Then, launch caffeine and its icon should appear in your system tray. You can choose which programs should cancel suspending.



      Note: As of the 2.7 release of caffeine, the program no longer has a GUI and works only as a daemon. When running, it will prevent the screensaver from activating so long as the active window is full screen.




    2. The LightsOn script. It won't check spotify by default but it is easy enough to modify it to do so. Just add spotify to the delay_progs array at the beginging of the script:



      delay_progs=("spotify")


      Then, add the script to your startup programs so it runs in the background. and it should stop you from suspending if spotify is running. Note that this does not check whether any music is playing, just whether the program is running.



    Let me know if these don't work for the suspension and I'll try and hack something together using xdotool or similar programs.







    share|improve this answer














    share|improve this answer



    share|improve this answer








    edited Jul 13 '16 at 22:24









    polemon

    5,48964076




    5,48964076










    answered Oct 4 '14 at 20:24









    terdon♦

    124k29233407




    124k29233407











    • I've used caffeine and it's worked alright in the past. It seems buggy though since I've had it active and the screensaver would still kick in. Haven't debugged it further, though.
      – slm♦
      Oct 5 '14 at 15:29










    • @slm I haven't so I can't speak as to how well it works. The second solution, the shell script, looks very interesting. It's relatively straightforward and should be easy to expand to blocking suspension.
      – terdon♦
      Oct 5 '14 at 15:33










    • yeah I was just giving a recounting of my experience. 2nd solution is prob. A better approach to try.
      – slm♦
      Oct 5 '14 at 15:35











    • The script looks pretty good. Could you add a line to your answer showing how to run the script at start-up?
      – LondonRob
      Oct 6 '14 at 22:25










    • @LondonRob that depends on your desktop environment but for most it's something along the lines of settings => startup programs. That's where you can find it on Cinnamon for example. Alternatively, copy the caffeine.desktop file from /usr/share/applications to ~/.config/autostart/.
      – terdon♦
      Oct 6 '14 at 22:39
















    • I've used caffeine and it's worked alright in the past. It seems buggy though since I've had it active and the screensaver would still kick in. Haven't debugged it further, though.
      – slm♦
      Oct 5 '14 at 15:29










    • @slm I haven't so I can't speak as to how well it works. The second solution, the shell script, looks very interesting. It's relatively straightforward and should be easy to expand to blocking suspension.
      – terdon♦
      Oct 5 '14 at 15:33










    • yeah I was just giving a recounting of my experience. 2nd solution is prob. A better approach to try.
      – slm♦
      Oct 5 '14 at 15:35











    • The script looks pretty good. Could you add a line to your answer showing how to run the script at start-up?
      – LondonRob
      Oct 6 '14 at 22:25










    • @LondonRob that depends on your desktop environment but for most it's something along the lines of settings => startup programs. That's where you can find it on Cinnamon for example. Alternatively, copy the caffeine.desktop file from /usr/share/applications to ~/.config/autostart/.
      – terdon♦
      Oct 6 '14 at 22:39















    I've used caffeine and it's worked alright in the past. It seems buggy though since I've had it active and the screensaver would still kick in. Haven't debugged it further, though.
    – slm♦
    Oct 5 '14 at 15:29




    I've used caffeine and it's worked alright in the past. It seems buggy though since I've had it active and the screensaver would still kick in. Haven't debugged it further, though.
    – slm♦
    Oct 5 '14 at 15:29












    @slm I haven't so I can't speak as to how well it works. The second solution, the shell script, looks very interesting. It's relatively straightforward and should be easy to expand to blocking suspension.
    – terdon♦
    Oct 5 '14 at 15:33




    @slm I haven't so I can't speak as to how well it works. The second solution, the shell script, looks very interesting. It's relatively straightforward and should be easy to expand to blocking suspension.
    – terdon♦
    Oct 5 '14 at 15:33












    yeah I was just giving a recounting of my experience. 2nd solution is prob. A better approach to try.
    – slm♦
    Oct 5 '14 at 15:35





    yeah I was just giving a recounting of my experience. 2nd solution is prob. A better approach to try.
    – slm♦
    Oct 5 '14 at 15:35













    The script looks pretty good. Could you add a line to your answer showing how to run the script at start-up?
    – LondonRob
    Oct 6 '14 at 22:25




    The script looks pretty good. Could you add a line to your answer showing how to run the script at start-up?
    – LondonRob
    Oct 6 '14 at 22:25












    @LondonRob that depends on your desktop environment but for most it's something along the lines of settings => startup programs. That's where you can find it on Cinnamon for example. Alternatively, copy the caffeine.desktop file from /usr/share/applications to ~/.config/autostart/.
    – terdon♦
    Oct 6 '14 at 22:39




    @LondonRob that depends on your desktop environment but for most it's something along the lines of settings => startup programs. That's where you can find it on Cinnamon for example. Alternatively, copy the caffeine.desktop file from /usr/share/applications to ~/.config/autostart/.
    – terdon♦
    Oct 6 '14 at 22:39












    up vote
    0
    down vote













    I just posted an answer for a similar question:
    Linux Mint: How to Avoid Suspending While Music is Playing



    I have written a script to set the suspend timeout to "Never" while pactl detects a running audio source, then reverts the setting when no audio sources are detected.



    Here is a copy of the latest answer and script:



    I have done a little more work on the above script and it should now work in Cinnamon, Mate and Ubuntu running Gnome. I have tried it out on Live USB versions of Linux Mint 19 Cinnamon and Mate as well as Ubuntu 18.04 - Gnome.



    #!/bin/sh

    # Audiocaffeine

    # Works in Linux Mint 19 - Cinnamon, Linux Mint 19 - Mate, Ubuntu 18.04 - Gnome

    # Script to temporarily set suspend timout for AC and battery to "Never"
    # while audio is playing. It then reverts the settings when audio is no longer detected.

    # Determine if a valid desktop environment is running and exit if it doesn't.
    echo "Reported desktop environment: ""$XDG_CURRENT_DESKTOP"
    if [ "$XDG_CURRENT_DESKTOP" = "X-Cinnamon" ]; then
    actimeoutid="org.cinnamon.settings-daemon.plugins.power sleep-inactive-ac-timeout"
    batttimeoutid="org.cinnamon.settings-daemon.plugins.power sleep-inactive-battery-timeout"
    disablevalue=0
    elif [ "$XDG_CURRENT_DESKTOP" = "MATE" ]; then
    actimeoutid="org.mate.power-manager sleep-computer-ac"
    batttimeoutid="org.mate.power-manager sleep-computer-battery"
    disablevalue=0
    elif [ "$XDG_CURRENT_DESKTOP" = "ubuntu:GNOME" ]; then
    actimeoutid="org.gnome.settings-daemon.plugins.power sleep-inactive-ac-type"
    batttimeoutid="org.gnome.settings-daemon.plugins.power sleep-inactive-battery-type"
    disablevalue="nothing"
    else
    echo "No valid desktop environment is running"
    exit 1
    fi

    # Create .config directory to store settings if it doesn't exist.
    if [ ! -d ~/.config ]; then
    echo ".config directory not found!"
    echo "Creating ~/.config"
    mkdir ~/.config
    fi

    # Create audiocaffeine directory to store settings if it doesn't exist.
    if [ ! -d ~/.config/audiocaffeine ]; then
    echo "Configuration directory not found!"
    echo "Creating ~/.config/audiocaffeine"
    mkdir ~/.config/audiocaffeine
    fi

    # Restore previous value for AC suspend timeout if script
    # was interrupted.
    if [ -f ~/.config/audiocaffeine/acsuspend ]; then
    echo "Restoring previous AC suspend timeout."
    read acsuspendtime < ~/.config/audiocaffeine/acsuspend
    gsettings set $actimeoutid $acsuspendtime
    echo "Removing temporary file ~/.config/audiocaffeine/acsuspend"
    rm ~/.config/audiocaffeine/acsuspend
    fi

    # Restore previous value for battery suspend timeout if script
    # was interrupted.
    if [ -f ~/.config/audiocaffeine/battsuspend ]; then
    echo "Restoring previous battery suspend timeout."
    read battsuspendtime < ~/.config/audiocaffeine/battsuspend
    gsettings set $batttimeoutid $battsuspendtime
    echo "Removing temporary file ~/.config/audiocaffeine/battsuspend"
    rm ~/.config/audiocaffeine/battsuspend
    fi

    # Start main loop to check if audio is playing

    while true; do

    # Use pactl to detect if there are any running audio sources.
    if pactl list | grep -q "State: RUNNING"; then

    echo "Audio detected."

    # If AC timeout was not previously saved, then save it.
    if [ ! -f ~/.config/audiocaffeine/acsuspend ]; then
    echo "Saving current AC suspend timeout."
    gsettings get $actimeoutid > ~/.config/audiocaffeine/acsuspend
    fi

    # If battery timeout was not previously saved, then save it.
    if [ ! -f ~/.config/audiocaffeine/battsuspend ]; then
    echo "Saving current battery suspend timeout."
    gsettings get $batttimeoutid > ~/.config/audiocaffeine/battsuspend
    fi

    # Set the suspend timouts to Never using gsettings.
    echo "Changing suspend timeouts."
    gsettings set $actimeoutid $disablevalue
    gsettings set $batttimeoutid $disablevalue

    else
    echo "No audio detected."

    # Restore previous value for AC suspend timeout and delete the
    # temporary file storing it.
    if [ -f ~/.config/audiocaffeine/acsuspend ]; then
    echo "Restoring previous AC suspend timeout."
    read acsuspendtime < ~/.config/audiocaffeine/acsuspend
    gsettings set $actimeoutid $acsuspendtime
    echo "Removing temporary file ~/.config/audiocaffeine/acsuspend"
    rm ~/.config/audiocaffeine/acsuspend
    fi

    # Restore previous value for battery suspend timeout and delete the
    # temporary file storing it.
    if [ -f ~/.config/audiocaffeine/battsuspend ]; then
    echo "Restoring previous battery suspend timeout."
    read battsuspendtime < ~/.config/audiocaffeine/battsuspend
    gsettings set $batttimeoutid $battsuspendtime
    echo "Removing temporary file ~/.config/audiocaffeine/battsuspend"
    rm ~/.config/audiocaffeine/battsuspend
    fi

    fi

    # Pause the script for 60 seconds before doing the loop again.
    sleep 60s

    done





    share|improve this answer


























      up vote
      0
      down vote













      I just posted an answer for a similar question:
      Linux Mint: How to Avoid Suspending While Music is Playing



      I have written a script to set the suspend timeout to "Never" while pactl detects a running audio source, then reverts the setting when no audio sources are detected.



      Here is a copy of the latest answer and script:



      I have done a little more work on the above script and it should now work in Cinnamon, Mate and Ubuntu running Gnome. I have tried it out on Live USB versions of Linux Mint 19 Cinnamon and Mate as well as Ubuntu 18.04 - Gnome.



      #!/bin/sh

      # Audiocaffeine

      # Works in Linux Mint 19 - Cinnamon, Linux Mint 19 - Mate, Ubuntu 18.04 - Gnome

      # Script to temporarily set suspend timout for AC and battery to "Never"
      # while audio is playing. It then reverts the settings when audio is no longer detected.

      # Determine if a valid desktop environment is running and exit if it doesn't.
      echo "Reported desktop environment: ""$XDG_CURRENT_DESKTOP"
      if [ "$XDG_CURRENT_DESKTOP" = "X-Cinnamon" ]; then
      actimeoutid="org.cinnamon.settings-daemon.plugins.power sleep-inactive-ac-timeout"
      batttimeoutid="org.cinnamon.settings-daemon.plugins.power sleep-inactive-battery-timeout"
      disablevalue=0
      elif [ "$XDG_CURRENT_DESKTOP" = "MATE" ]; then
      actimeoutid="org.mate.power-manager sleep-computer-ac"
      batttimeoutid="org.mate.power-manager sleep-computer-battery"
      disablevalue=0
      elif [ "$XDG_CURRENT_DESKTOP" = "ubuntu:GNOME" ]; then
      actimeoutid="org.gnome.settings-daemon.plugins.power sleep-inactive-ac-type"
      batttimeoutid="org.gnome.settings-daemon.plugins.power sleep-inactive-battery-type"
      disablevalue="nothing"
      else
      echo "No valid desktop environment is running"
      exit 1
      fi

      # Create .config directory to store settings if it doesn't exist.
      if [ ! -d ~/.config ]; then
      echo ".config directory not found!"
      echo "Creating ~/.config"
      mkdir ~/.config
      fi

      # Create audiocaffeine directory to store settings if it doesn't exist.
      if [ ! -d ~/.config/audiocaffeine ]; then
      echo "Configuration directory not found!"
      echo "Creating ~/.config/audiocaffeine"
      mkdir ~/.config/audiocaffeine
      fi

      # Restore previous value for AC suspend timeout if script
      # was interrupted.
      if [ -f ~/.config/audiocaffeine/acsuspend ]; then
      echo "Restoring previous AC suspend timeout."
      read acsuspendtime < ~/.config/audiocaffeine/acsuspend
      gsettings set $actimeoutid $acsuspendtime
      echo "Removing temporary file ~/.config/audiocaffeine/acsuspend"
      rm ~/.config/audiocaffeine/acsuspend
      fi

      # Restore previous value for battery suspend timeout if script
      # was interrupted.
      if [ -f ~/.config/audiocaffeine/battsuspend ]; then
      echo "Restoring previous battery suspend timeout."
      read battsuspendtime < ~/.config/audiocaffeine/battsuspend
      gsettings set $batttimeoutid $battsuspendtime
      echo "Removing temporary file ~/.config/audiocaffeine/battsuspend"
      rm ~/.config/audiocaffeine/battsuspend
      fi

      # Start main loop to check if audio is playing

      while true; do

      # Use pactl to detect if there are any running audio sources.
      if pactl list | grep -q "State: RUNNING"; then

      echo "Audio detected."

      # If AC timeout was not previously saved, then save it.
      if [ ! -f ~/.config/audiocaffeine/acsuspend ]; then
      echo "Saving current AC suspend timeout."
      gsettings get $actimeoutid > ~/.config/audiocaffeine/acsuspend
      fi

      # If battery timeout was not previously saved, then save it.
      if [ ! -f ~/.config/audiocaffeine/battsuspend ]; then
      echo "Saving current battery suspend timeout."
      gsettings get $batttimeoutid > ~/.config/audiocaffeine/battsuspend
      fi

      # Set the suspend timouts to Never using gsettings.
      echo "Changing suspend timeouts."
      gsettings set $actimeoutid $disablevalue
      gsettings set $batttimeoutid $disablevalue

      else
      echo "No audio detected."

      # Restore previous value for AC suspend timeout and delete the
      # temporary file storing it.
      if [ -f ~/.config/audiocaffeine/acsuspend ]; then
      echo "Restoring previous AC suspend timeout."
      read acsuspendtime < ~/.config/audiocaffeine/acsuspend
      gsettings set $actimeoutid $acsuspendtime
      echo "Removing temporary file ~/.config/audiocaffeine/acsuspend"
      rm ~/.config/audiocaffeine/acsuspend
      fi

      # Restore previous value for battery suspend timeout and delete the
      # temporary file storing it.
      if [ -f ~/.config/audiocaffeine/battsuspend ]; then
      echo "Restoring previous battery suspend timeout."
      read battsuspendtime < ~/.config/audiocaffeine/battsuspend
      gsettings set $batttimeoutid $battsuspendtime
      echo "Removing temporary file ~/.config/audiocaffeine/battsuspend"
      rm ~/.config/audiocaffeine/battsuspend
      fi

      fi

      # Pause the script for 60 seconds before doing the loop again.
      sleep 60s

      done





      share|improve this answer
























        up vote
        0
        down vote










        up vote
        0
        down vote









        I just posted an answer for a similar question:
        Linux Mint: How to Avoid Suspending While Music is Playing



        I have written a script to set the suspend timeout to "Never" while pactl detects a running audio source, then reverts the setting when no audio sources are detected.



        Here is a copy of the latest answer and script:



        I have done a little more work on the above script and it should now work in Cinnamon, Mate and Ubuntu running Gnome. I have tried it out on Live USB versions of Linux Mint 19 Cinnamon and Mate as well as Ubuntu 18.04 - Gnome.



        #!/bin/sh

        # Audiocaffeine

        # Works in Linux Mint 19 - Cinnamon, Linux Mint 19 - Mate, Ubuntu 18.04 - Gnome

        # Script to temporarily set suspend timout for AC and battery to "Never"
        # while audio is playing. It then reverts the settings when audio is no longer detected.

        # Determine if a valid desktop environment is running and exit if it doesn't.
        echo "Reported desktop environment: ""$XDG_CURRENT_DESKTOP"
        if [ "$XDG_CURRENT_DESKTOP" = "X-Cinnamon" ]; then
        actimeoutid="org.cinnamon.settings-daemon.plugins.power sleep-inactive-ac-timeout"
        batttimeoutid="org.cinnamon.settings-daemon.plugins.power sleep-inactive-battery-timeout"
        disablevalue=0
        elif [ "$XDG_CURRENT_DESKTOP" = "MATE" ]; then
        actimeoutid="org.mate.power-manager sleep-computer-ac"
        batttimeoutid="org.mate.power-manager sleep-computer-battery"
        disablevalue=0
        elif [ "$XDG_CURRENT_DESKTOP" = "ubuntu:GNOME" ]; then
        actimeoutid="org.gnome.settings-daemon.plugins.power sleep-inactive-ac-type"
        batttimeoutid="org.gnome.settings-daemon.plugins.power sleep-inactive-battery-type"
        disablevalue="nothing"
        else
        echo "No valid desktop environment is running"
        exit 1
        fi

        # Create .config directory to store settings if it doesn't exist.
        if [ ! -d ~/.config ]; then
        echo ".config directory not found!"
        echo "Creating ~/.config"
        mkdir ~/.config
        fi

        # Create audiocaffeine directory to store settings if it doesn't exist.
        if [ ! -d ~/.config/audiocaffeine ]; then
        echo "Configuration directory not found!"
        echo "Creating ~/.config/audiocaffeine"
        mkdir ~/.config/audiocaffeine
        fi

        # Restore previous value for AC suspend timeout if script
        # was interrupted.
        if [ -f ~/.config/audiocaffeine/acsuspend ]; then
        echo "Restoring previous AC suspend timeout."
        read acsuspendtime < ~/.config/audiocaffeine/acsuspend
        gsettings set $actimeoutid $acsuspendtime
        echo "Removing temporary file ~/.config/audiocaffeine/acsuspend"
        rm ~/.config/audiocaffeine/acsuspend
        fi

        # Restore previous value for battery suspend timeout if script
        # was interrupted.
        if [ -f ~/.config/audiocaffeine/battsuspend ]; then
        echo "Restoring previous battery suspend timeout."
        read battsuspendtime < ~/.config/audiocaffeine/battsuspend
        gsettings set $batttimeoutid $battsuspendtime
        echo "Removing temporary file ~/.config/audiocaffeine/battsuspend"
        rm ~/.config/audiocaffeine/battsuspend
        fi

        # Start main loop to check if audio is playing

        while true; do

        # Use pactl to detect if there are any running audio sources.
        if pactl list | grep -q "State: RUNNING"; then

        echo "Audio detected."

        # If AC timeout was not previously saved, then save it.
        if [ ! -f ~/.config/audiocaffeine/acsuspend ]; then
        echo "Saving current AC suspend timeout."
        gsettings get $actimeoutid > ~/.config/audiocaffeine/acsuspend
        fi

        # If battery timeout was not previously saved, then save it.
        if [ ! -f ~/.config/audiocaffeine/battsuspend ]; then
        echo "Saving current battery suspend timeout."
        gsettings get $batttimeoutid > ~/.config/audiocaffeine/battsuspend
        fi

        # Set the suspend timouts to Never using gsettings.
        echo "Changing suspend timeouts."
        gsettings set $actimeoutid $disablevalue
        gsettings set $batttimeoutid $disablevalue

        else
        echo "No audio detected."

        # Restore previous value for AC suspend timeout and delete the
        # temporary file storing it.
        if [ -f ~/.config/audiocaffeine/acsuspend ]; then
        echo "Restoring previous AC suspend timeout."
        read acsuspendtime < ~/.config/audiocaffeine/acsuspend
        gsettings set $actimeoutid $acsuspendtime
        echo "Removing temporary file ~/.config/audiocaffeine/acsuspend"
        rm ~/.config/audiocaffeine/acsuspend
        fi

        # Restore previous value for battery suspend timeout and delete the
        # temporary file storing it.
        if [ -f ~/.config/audiocaffeine/battsuspend ]; then
        echo "Restoring previous battery suspend timeout."
        read battsuspendtime < ~/.config/audiocaffeine/battsuspend
        gsettings set $batttimeoutid $battsuspendtime
        echo "Removing temporary file ~/.config/audiocaffeine/battsuspend"
        rm ~/.config/audiocaffeine/battsuspend
        fi

        fi

        # Pause the script for 60 seconds before doing the loop again.
        sleep 60s

        done





        share|improve this answer














        I just posted an answer for a similar question:
        Linux Mint: How to Avoid Suspending While Music is Playing



        I have written a script to set the suspend timeout to "Never" while pactl detects a running audio source, then reverts the setting when no audio sources are detected.



        Here is a copy of the latest answer and script:



        I have done a little more work on the above script and it should now work in Cinnamon, Mate and Ubuntu running Gnome. I have tried it out on Live USB versions of Linux Mint 19 Cinnamon and Mate as well as Ubuntu 18.04 - Gnome.



        #!/bin/sh

        # Audiocaffeine

        # Works in Linux Mint 19 - Cinnamon, Linux Mint 19 - Mate, Ubuntu 18.04 - Gnome

        # Script to temporarily set suspend timout for AC and battery to "Never"
        # while audio is playing. It then reverts the settings when audio is no longer detected.

        # Determine if a valid desktop environment is running and exit if it doesn't.
        echo "Reported desktop environment: ""$XDG_CURRENT_DESKTOP"
        if [ "$XDG_CURRENT_DESKTOP" = "X-Cinnamon" ]; then
        actimeoutid="org.cinnamon.settings-daemon.plugins.power sleep-inactive-ac-timeout"
        batttimeoutid="org.cinnamon.settings-daemon.plugins.power sleep-inactive-battery-timeout"
        disablevalue=0
        elif [ "$XDG_CURRENT_DESKTOP" = "MATE" ]; then
        actimeoutid="org.mate.power-manager sleep-computer-ac"
        batttimeoutid="org.mate.power-manager sleep-computer-battery"
        disablevalue=0
        elif [ "$XDG_CURRENT_DESKTOP" = "ubuntu:GNOME" ]; then
        actimeoutid="org.gnome.settings-daemon.plugins.power sleep-inactive-ac-type"
        batttimeoutid="org.gnome.settings-daemon.plugins.power sleep-inactive-battery-type"
        disablevalue="nothing"
        else
        echo "No valid desktop environment is running"
        exit 1
        fi

        # Create .config directory to store settings if it doesn't exist.
        if [ ! -d ~/.config ]; then
        echo ".config directory not found!"
        echo "Creating ~/.config"
        mkdir ~/.config
        fi

        # Create audiocaffeine directory to store settings if it doesn't exist.
        if [ ! -d ~/.config/audiocaffeine ]; then
        echo "Configuration directory not found!"
        echo "Creating ~/.config/audiocaffeine"
        mkdir ~/.config/audiocaffeine
        fi

        # Restore previous value for AC suspend timeout if script
        # was interrupted.
        if [ -f ~/.config/audiocaffeine/acsuspend ]; then
        echo "Restoring previous AC suspend timeout."
        read acsuspendtime < ~/.config/audiocaffeine/acsuspend
        gsettings set $actimeoutid $acsuspendtime
        echo "Removing temporary file ~/.config/audiocaffeine/acsuspend"
        rm ~/.config/audiocaffeine/acsuspend
        fi

        # Restore previous value for battery suspend timeout if script
        # was interrupted.
        if [ -f ~/.config/audiocaffeine/battsuspend ]; then
        echo "Restoring previous battery suspend timeout."
        read battsuspendtime < ~/.config/audiocaffeine/battsuspend
        gsettings set $batttimeoutid $battsuspendtime
        echo "Removing temporary file ~/.config/audiocaffeine/battsuspend"
        rm ~/.config/audiocaffeine/battsuspend
        fi

        # Start main loop to check if audio is playing

        while true; do

        # Use pactl to detect if there are any running audio sources.
        if pactl list | grep -q "State: RUNNING"; then

        echo "Audio detected."

        # If AC timeout was not previously saved, then save it.
        if [ ! -f ~/.config/audiocaffeine/acsuspend ]; then
        echo "Saving current AC suspend timeout."
        gsettings get $actimeoutid > ~/.config/audiocaffeine/acsuspend
        fi

        # If battery timeout was not previously saved, then save it.
        if [ ! -f ~/.config/audiocaffeine/battsuspend ]; then
        echo "Saving current battery suspend timeout."
        gsettings get $batttimeoutid > ~/.config/audiocaffeine/battsuspend
        fi

        # Set the suspend timouts to Never using gsettings.
        echo "Changing suspend timeouts."
        gsettings set $actimeoutid $disablevalue
        gsettings set $batttimeoutid $disablevalue

        else
        echo "No audio detected."

        # Restore previous value for AC suspend timeout and delete the
        # temporary file storing it.
        if [ -f ~/.config/audiocaffeine/acsuspend ]; then
        echo "Restoring previous AC suspend timeout."
        read acsuspendtime < ~/.config/audiocaffeine/acsuspend
        gsettings set $actimeoutid $acsuspendtime
        echo "Removing temporary file ~/.config/audiocaffeine/acsuspend"
        rm ~/.config/audiocaffeine/acsuspend
        fi

        # Restore previous value for battery suspend timeout and delete the
        # temporary file storing it.
        if [ -f ~/.config/audiocaffeine/battsuspend ]; then
        echo "Restoring previous battery suspend timeout."
        read battsuspendtime < ~/.config/audiocaffeine/battsuspend
        gsettings set $batttimeoutid $battsuspendtime
        echo "Removing temporary file ~/.config/audiocaffeine/battsuspend"
        rm ~/.config/audiocaffeine/battsuspend
        fi

        fi

        # Pause the script for 60 seconds before doing the loop again.
        sleep 60s

        done






        share|improve this answer














        share|improve this answer



        share|improve this answer








        edited Sep 7 at 23:00









        Rui F Ribeiro

        36.8k1273117




        36.8k1273117










        answered Aug 8 at 2:52









        Jason Gambrel

        212




        212



























             

            draft saved


            draft discarded















































             


            draft saved


            draft discarded














            StackExchange.ready(
            function ()
            StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2funix.stackexchange.com%2fquestions%2f159286%2fprevent-mint-from-suspending-while-playing-music-in-spotify%23new-answer', 'question_page');

            );

            Post as a guest













































































            Popular posts from this blog

            How to check contact read email or not when send email to Individual?

            Bahrain

            Postfix configuration issue with fips on centos 7; mailgun relay