caffeine-ng icon indicating copy to clipboard operation
caffeine-ng copied to clipboard

How do I toggle Caffeine?

Open yusi1 opened this issue 3 years ago • 6 comments

My window manager supports launching commands with shortcuts such as ALT + F9 for example.

Is there any way to toggle Caffeine's inhibitor, I tried to bind caffeine -a & and caffeine -d & to separate shortcuts, but by running them commands, the output was that Caffeine was already running. Is there a way to toggle Caffeine from the command line, if there was a way to toggle it on and off it would also mean that I would only have to use one shortcut, instead of two.

I have checked if people have done this, but it was with separate bash scripts (not that I have a problem with using bash scripts) but if there was a more streamlined way of doing this it would be helpful.

But I have to also say how useful this program is when I just want the computer to not sleep, thank you for making this program.

yusi1 avatar Jul 08 '21 19:07 yusi1

Closing since this is not really an issue.

yusi1 avatar Jul 09 '21 19:07 yusi1

There should be a way to control caffeine via the cli (especially for desktops with a tray).

WhyNotHugo avatar Jul 10 '21 09:07 WhyNotHugo

I have checked if people have done this, but it was with separate bash scripts (not that I have a problem with using bash scripts) but if there was a more streamlined way of doing this it would be helpful.

I ended up writing a little toggle script since I couldn't find one online. For some reason, killall and pgrep couldn't find caffeine-ng in the running processes, but pidof worked so I used that. I use zsh but I'm pretty sure it's compatible with bash as well.

#!/usr/bin/env zsh

caffeinePID=$(pidof caffeine-ng) || caffeine -a

[[ -z "$caffeinePID" ]] || kill -15 $caffeinePID

If it can't find caffeine's PID, it starts it, and if it can, it kills it. I'm not sure if it's POSIX compliant and it could potentially be compressed into a one-liner.

Still, I have it bound to a keyboard shortcut in i3 and it works fine. Hopefully this saves someone else the time of figuring out a script until this feature is implemented.

Herschenglime avatar Jul 26 '21 20:07 Herschenglime

I keep coming back to this problem and thinking of exposing some API, but I fear having yet-another-inhibition API:

XKCD 927

I think I'm going to have caffeine expose the existing inhibition D-Bus API, and cli client to operate on that.

However, this needs to be well though-through in order to avoid shadowing any actual service already exposing that API.

WhyNotHugo avatar Aug 02 '21 20:08 WhyNotHugo

This seems a little bit like what I wanted in #39 -- a way to just manually turn inhibition on and off, with absolutely no auto-detection or the like at all. This is, in fact, a dealbreaker to me, and I've been using an app called Wakefull in the meantime, in the hopes that eventually the pre-version-2.5 behavior of Caffeine would be re-implemented. It really seems like a "stupid mode" or "manual mode" ought to be an option, somehow.

frankspace avatar Aug 08 '21 17:08 frankspace

Also there is currently no way to change caffeine settings without indicator panel.

akhilman avatar Jan 01 '22 06:01 akhilman

This project has moved to codeberg.

Follow-up for this issue is at https://codeberg.org/WhyNotHugo/caffeine-ng/issues/71

WhyNotHugo avatar Nov 06 '22 14:11 WhyNotHugo