nosleep icon indicating copy to clipboard operation
nosleep copied to clipboard

Doesn't work under macOS Catalina

Open mattjonsson opened this issue 5 years ago • 3 comments

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

mattjonsson avatar Oct 08 '19 12:10 mattjonsson

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

oddguan avatar May 28 '20 19:05 oddguan

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

dschuessler avatar May 28 '20 20:05 dschuessler

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

oddguan avatar May 29 '20 00:05 oddguan