Spotify Prevents MacOS to Sleep Fix

Spotify Prevents MacOS to Sleep

Having some time these days – with holidays and stuff – decided to see why my Macbook Pro does not sleep when I close the lid.

The short explanation is that after you open Spotify and play a song, the program will prevent your system to sleep. It’s a very known old bug from 8 years ago now.

spotify prevents mac sleep

There is a relatively quick fix for that:

    1. Install Homebrew – a package manager for Mac:
      /usr/bin/ruby -e "$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/master/install)"
    2. Install sleepwatcher – it monitors sleep wakeup and idleness of a Mac: brew install sleepwatcher
    3. Create a .sleep file for sleepwatcher to execute when we close the lid. Run the command: echo "osascript -e 'tell application "\"Spotify"\" to quit'" >> ~/.sleep && chmod +x ~/.sleep
    4. (optional) if you want Spotify to resume playing at system wake-up, run this: echo "osascript -e 'tell application "\"Spotify"\" to play'" >> ~/.wakeup && chmod +x ~/.wakeup
    5. Run it as a service. If you don’t have enabled homebrew services, you must run this command brew tap homebrew/services and then run sleepwatcher as a service: brew services start sleepwatcher

That’s all. Now, you can test it by having the Spotify MacOS app running, then close the lid and wait few seconds until the system sleep. Re-open the lid and you should have your Spotify app closed.

Tested on macOS Catalina 10.15.2.

Waiting for your feedback! 🙂

Silviu Stroe
I'm Silviu and I run Brainic, a mobile-focused software agency. I'm also a member of Nokia and Yahoo wall of fame. My interests are in low-code/no-code development and bleeding-edge technologies.

9 thoughts on “Spotify Prevents MacOS to Sleep Fix”

  1. Hi Silviu,

    Thank you so much for this article! My Mac not sleeping properly has been bugging for ages and your solution is brilliant. My monitor says a huge thank you :).

    By the way, step 4 appears to be missing “echo” at the start of the line.

    As an aside, I found running `pmset -g assertions | grep PreventUserIdleSystemSleep` helpful for diagnosing what is preventing sleep in general. You may well have come across this and may not be worth including in your most excellent article.

    Thanks again.

  2. Hi, Grum,

    I’m glad that the solution works for you.
    Regarding step 4, the “echo” exists, but it’s on the previous line.

    Thanks

  3. anyway ‘brew services start sleepwatcher’ can be run at startup? so you don’t have to remember to do it?

  4. Dear Silviu,

    I installed everything and it works fine – however, how do I uninstall – or disable the resuming of spotify after waking up? Is there a command line for that as well?

    Best,

    Jack

    1. Sorry for the late response, Jack.
      You can delete the .wakeup file. The command for that would be: rm ~/.wakeup

  5. i tried to delete the wakeup file but it says:

    .wakeup: No such file or directory

    it has been working fine but i just want to remove the auto play on wake, the sleep is sufficient.

Leave a Reply

Your email address will not be published. Required fields are marked *