Prevent sleep when running specific command

Hello,

I’m looking for

1° a non-privileged command X such that, for all commands Y, X Y runs command Y in such a way that the computer cannot go to sleep during execution of Y.

for instance, X rsync ... should run my rsync with no danger of the transfer being interrupted by sleep, and when it’s done, sleep can occur again.

I understand that on Mac, caffeinate -i can play the role of X.

systemd-inhibit can do that [1], but it requires root. qbittorrent is capable of doing that for itself without being root, so this has to be implementable without root privileges. Moving the mouse does not require root either, so it’s absurd that you should need to be root to prevent sleep.

I assume this could be implemented rather simply by having X spawn a process that does, say, xdotool key <somekey> or better yet xdotool mousemove ... in a loop (ydotool for wayland?). But if it is that simple surely the command already exists.

[1] https://askubuntu.com/questions/973388/can-i-prevent-my-time-consuming-backup-command-from-being-interrupted-by-system


2° a way of exempting a program from sleep globally and permanently, as though always run with X. For instance, exempting rsync globally.

For instance, in the case of a remote X rsync ..., the other machine may go to sleep. I’d like all my machines to understand that rsync must not be interrupted, thankyouverymuch.

I have no idea how to do that. (Although if X exists, then you could manually replace executable Y with X Y, but that’s super-ugly)

I’d accept a solution that requires root and/or is a GUI (edit: actually I want that in my install scripts, so GUIs are only partial solutions for that)


Thoughts?