integralpro / nosleep

The MacOS X kernel extension, preventing sleep when you close the lid.
GNU General Public License v2.0
874 stars 45 forks source link

Doesn't work under macOS Catalina #46

Open mattjonsson opened 4 years ago

mattjonsson commented 4 years ago

MacBook Pro goes to sleep 15 seconds after closing the lid with NoSleep enabled.

oddguan commented 4 years ago

Is there still no solution to this problem? Is this project still being maintained?

dschuessler commented 4 years ago

I switched to Hammerspoon and replicated the functionality with the following script:

-- Menu bar icon for keeping Mac from sleeping when closing lid
local noSleep = hs.menubar.new()
local noSleepState = false
hs.execute("sudo pmset -b disablesleep 0")

function setNoSleepDisplay(state)
    if state then
        noSleep:setIcon("ZzActive.pdf")
    else
        noSleep:setIcon("ZzInactive.pdf")
    end
end

function noSleepClicked()
    if noSleepState then
        hs.execute("sudo pmset -b disablesleep 0", true)
        noSleepState = false
    else
        hs.execute("sudo pmset -b disablesleep 1", true)
        noSleepState = true 
    end 

    setNoSleepDisplay(noSleepState)
end

if noSleep then
    noSleep:setClickCallback(noSleepClicked)
    setNoSleepDisplay(false)
end

You have to copy ZzActive.pdf and ZzInactive.pdf from /Applications/NoSleep.app/Contents/Resources over to ~/.hammerspoon for it to work.

I stayed on Mojave so I don't know if it works with Catalina. Anyone who wants to test this on Catalina, please let us know.

EDIT: I forgot that you also have to add the following lines to /etc/sudoers/ via visudo for this to work:

yourusername          ALL = (root) NOPASSWD: /usr/bin/pmset -b disablesleep 0
yourusername          ALL = (root) NOPASSWD: /usr/bin/pmset -b disablesleep 1
oddguan commented 4 years ago

Thanks for the solution. I switched to Amphetamine and it works like a charm (plus it is free as well).