Skip to content

Instantly share code, notes, and snippets.

@adam-currie
Last active May 26, 2022 19:20
Show Gist options
  • Save adam-currie/bdf1f8e94f3eceb7f87ec2accceb4df2 to your computer and use it in GitHub Desktop.
Save adam-currie/bdf1f8e94f3eceb7f87ec2accceb4df2 to your computer and use it in GitHub Desktop.
runs a command as another user with current users x server
#!/bin/bash
selfBaseName=$(basename -- "$(readlink -f -- "$0")")
usage="Usage: ${selfBaseName} <username> <command>"
if test $# -ne 2; then
echo $usage
exit
fi
user=$1
cmd=$2
xhost +SI:localuser:$user
pkexec --user $user env DISPLAY=$DISPLAY XAUTHORITY=$XAUTHORITY $cmd
xhost -SI:localuser:$user
@adam-currie
Copy link
Author

works with zsh, toss in /usr/local/bin or equivalent

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment