]>
code.delx.au - monosys/blob - bin/xuserrun
5 # Run a command as the currently active X11 user
10 # determine location of loginctl
11 LOGINCTL
=$
(command -v loginctl ||
command -v systemd-loginctl
)
12 if [[ -e LOGINCTL
]]; then
13 echo "Error: Unable to find loginctl executable"
21 eval declare -Ag $varname
22 for row
in $
(loginctl show-session
"$session"); do
23 key
="$(echo "${row}"|cut -d= -f1)"
24 val
="$(echo "${row}"|cut -d= -f2-)"
25 eval ${varname}[\"${key}\"]=\"${val}\"
35 session_list
="$(loginctl --no-legend | grep "$seat" | awk '{print $1}')"
36 found_active_session
=""
37 for session
in $session_list; do
38 get_session_info
"$session" session_info
39 if [[ "${session_info[Active]}" = "yes" ]]; then
40 found_active_session
="yes"
44 if [ -z "${found_active_session}" ]; then
45 echo "Error: Unable to determine active session"
49 if [[ "${session_info[Type]}" != "x11" ]]; then
50 echo "Error: Active session is not x11"
54 current_user
="$(id -u -n)"
56 if [[ ${current_user} == ${session_info[Name]} ]]; then
57 # already correct user, no need to su
58 DISPLAY
="${session_info[Display]}" "$@"
61 DISPLAY
="${session_info[Display]}" su
-c - "${session_info[Name]}" "$(escape "$@
")"