Hacker Newsnew | past | comments | ask | show | jobs | submit | clash's commentslogin

Yeah, most of these repositories contain more files than caffeinate+ has lines of code.

The API call that 'sudo pmset -a disablesleep 1' does is literally the first thing caffeine+ does. But is only part of the full solution: As soon as the lid closes the command is automatically reverted so you can't forget to do it yourself. Also if you kill caffeinate+, the MacBook is put to sleep when the lid is still closed.


Yes, most of the very many that you didn't know existed just a moment ago also handle that tricky case of restoring normal operation.


Bold accusation ;)

You forgot to argue about the LOC vs file count issue.

Also, you are wrong: None does auto sleep on script exit.


Oops, didn't follow user names. My mistake.

And, I've been using these for around 9 years. A few I tried most definitely did re-enable on exit. Not sure why file count is a concern, or especially LOC (a truly horrendous metric to target, with the outcome being unintelligible code golf when optimized for). All that I used were exactly one file I was concerned with: a binary or shell script.

This has become strange. Cheers!


Obviously code-golfed LOC is bullshit. 50 files and GUI for a near-trivial functionality is excessive, though.


Yeah, I obviously also did the research prior to implementing my solution.

I did not want GUI, just super simple caffeinate-like CLI. Also I wanted auto-shutdown afterwards.


Can your one line terminal invocation automatically put the MacBook to sleep when you are connected via ssh and the connection is lost?


Technically one line ;)

    sudo bash -c 'trap "pmset -a disablesleep 0" EXIT; s=; while :; do if lsof -nP -iTCP:22 -sTCP:ESTABLISHED >/dev/null 2>&1 || pgrep -xq ssh;
  then n=1; else n=0; fi; [ "$n" != "$s" ] && pmset -a disablesleep $n && s=$n; sleep 10; done'


Nope, not thanking you now or later.

1) It is an insane bloat if you just want that one feature. 2) There is no CLI, just GUI.


I found this before I implemented my solution and it did not solve my problem:

1) It does not behave like caffeine where I can just kill the process and the behavior is reverted.

2) It does not put the MacBook to sleep automatically.


2. yes it does


1) Because you will eventually forget to reactivate it, which then leads to obvious problems.

2) Because you can for example be connected via ssh: You run the script and if your connection is disconnected, caffeinate+ shuts down the MacBook.

Edit: The API call that 'sudo pmset -a disablesleep 1' does is literally the first thing caffeine+ does. As soon as the lid closes the command is automatically reverted so you can't forget to do it yourself.


Both of those are trivial to do in a few lines of shell. There's no need to write or download a custom tool for this. I asked Opus to draft one up and it's just five lines long.

    #!/bin/bash
    [ "$EUID" = 0 ] || exec sudo "$0" "$@"
    pmset -a disablesleep 1
    trap exit HUP INT TERM
    trap 'pmset -a disablesleep 0; ioreg -r -k AppleClamshellState | grep -q "State\" = Yes" && pmset sleepnow' EXIT
    "${@:-read}"
How to use it:

    ./caf.sh              # stay awake until you press Enter
    ./caf.sh make build   # stay awake only while the command runs
Sleep is re-enabled when: the command finishes, the user presses Enter, on Ctrl-C, on SSH disconnect, or on kill (excluding SIGKILL). If the lid is closed when the command finishes, sleep is re-enabled and the Mac goes to sleep.


You say "No need to write a tool", then immediately write a tool. Brilliant :)

My first attempt was a shell script almost exactly like yours. Then I thought I want to be able to set SUID so I don't have to use sudo. This ruled out the shell script. I could have just done a bunch of 'system("pmset ...")' calls but thought I might as well use the native commands.


I wrote a small caffeine-like macOS command-line utility to keep your MacBook awake when you close the lid.

This can be handy when you have a long running task active but need to close your MacBook – for example to change trains, head home from a café or commute to the office.


> I wrote a small caffeine-like macOS command-line utility to keep your MacBook awake when you close the lid.

Small purposeful utilities like this are Glob's own gift to us. Your counterpart in my Windows world might be the guy who wrote AlwaysActiveHours - a util that prevents update-related reboots.


"Active Hours"? Who comes up with that kind of stuff? And you cannot even disable it, only out"smart" it. Unbelievable.


Haha, every operating system has its quirks. The auto reboot is certainly a very nasty one.


This is an easy one:

bool isRestricted(uint8_t* /* data */) { return true; } // Might catch a few false positives

and

popup("This is a restricted model. If you are not in the state of New York, please flash the international firmware ([link]) to print restricted parts.");

It can also handle STL, step and all kinds of other formats.


You left out the higher entity that takes away a significant portion of the snow that was accumulated at regular intervals.

It doesn't need to ruin the metaphor, though: The sun could do that job. It could also explain the fact that the portion that's taken differs depending on where on earth you are creating the snowball.


This appears to be even more of a problem with EVs and their regenerative breaking and I wonder whether this could not be easily fixed by software: "Breaks were not used recently or car did not move in some time? ⟹ Temporarily disable regenerative breaking for a few minutes until the break pads can be assumed to be clear again."


Guidelines | FAQ | Lists | API | Security | Legal | Apply to YC | Contact

Search: