Hacker News new | past | comments | ask | show | jobs | submit login

TIL: caffeinate

Very useful.






For a GUI version, Amphetamine is quite nice (and free). https://apps.apple.com/us/app/amphetamine/id937984704?mt=12

yes amphetamine I use regularly when I want to charge my android phone during travel with lid closed.

That's interesting, I have never needed to do that. My Pixels have always just charged even if the lid is closed, on Intel and Apple Silicon machines. I like to travel light so I often use my laptop as a battery bank instead of carrying a seperate one.

Indeed, many applications I would expect to prevent sleeping (some audio playback ones, games, etc.) don't implement this. I assume it's a case of Apple's APIs changing over the years and not everyone catching up/caring. At one point I had downloaded Amphetamine[^1] but it is much nicer to just use the terminal here.

[^1]: https://apps.apple.com/us/app/amphetamine/id937984704




I was able to install a `caffeine` package with Apt on Linux. In that one the `caffeinate` command is supposed to be run with another command. While the `caffeine` command does what macOs `caffeinate` does.

While it may avoid sleep, it doesn’t prevent inactivity, in my experience. For instance, my chat app at work will still show me inactive while running caffeinate. I have to do non-interactive training semi-regularly and need to interact to keep from looking like I’m away from my desk.

Have you used the `-u` flag? From the manual:

  -u      Create an assertion to declare that user is active.

Doesn’t work with Slack at least. I’ve had an iTerm window running `caffeinate -disu` for years. I think it used to work and stopped working in the last few months.

It would be cool to have this activate when a Jupyter notebook is currently running a cell, and deactivate automatically when its finished.

This can be done by passing a PID. I believe there are other options, as well. (Not at my computer to look it up right now.) I haven't used those features "manually", but I have in scripts that I expect to generate long-running processes.



Consider applying for YC's W25 batch! Applications are open till Nov 12.

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

Search: