[Date Prev][Date Next] [Thread Prev][Thread Next] [Date Index] [Thread Index]

Re: Change suspend type from kde menu



On Wed, Jan 03, 2024 at 05:18:19PM +0100, Franco Martelli wrote:
>             /usr/bin/su YOURUSER -c 'XDG_RUNTIME_DIR=/run/user/1000
> DISPLAY=:0 XDG_CURRENT_DESKTOP=KDE /usr/bin/kaffeine >/dev/null 2>&1 &'

> In place of YOURUSER you've to put your username, if you doubt the command
> "whoami" will tell you. Check if XDG_RUNTIME_DIR, XDG_CURRENT_DESKTOP and
> DISPLAY have the same value that I set, use the command "echo $variableName"
> to verify.

The UID of 1000 will have to be verified, as well as the YOURUSER.
UID 1000 is what Debian uses for the initial user account that's
created during installation, but if for some reason that's not the
account who's currently logged in, then obviously this won't work.

The su command is not an ideal choice for this, in fact.  The setpriv(1)
command is better suited for running programs as other user accounts,
without doing crazy PAM stuff like su does.  It also has the advantage
of not needing a username -- it can work with just the UID.

    uid=1000 gid=1000
    setpriv --reuid "$uid" --regid "$gid" --init-groups \
      env XDG_RUNTIME_DIR=/run/user/"$uid" DISPLAY=:0 XDG_CURRENT_DESKTOP=KDE \
      keffeine >/dev/null 2>&1 &

Bear in mind that this entire approach is a bit of a hack, with some
baked-in assumptions about who's logged in on which DISPLAY.  If this
works for you, then that's great.  But some people might need to extend
this to check for the actual logged-in account, rather than assuming it's
the primary user.  (Left as an exercise, because unfortunately there is
no good way to do that, as far as I know anyway.)


Reply to: