Project

General

Profile

Unable to use audtool, as root or with sudo, to get the state of audacious run by a specific user

Added by John Christopher about 10 years ago

Hello,

I want to poll the state of audacious in my acpi /etc/acpi/sleep.sh script so I can pause it when going to suspend mode.

This works:
~ $ audtool playback-status # returns the actual state of audacious
This works:
~ # sudo -u $USER bash -c 'whoami' # returns $USER
but those don't:
~ # sudo -u $USER bash -c 'audtool playback-status' # always returns 'stopped'
~ # su -c 'audtool playback-status' jeankri # always returns 'stopped'

I can't tell if I am missing something with sudo/su or with audpool.


Replies (1)

RE: Unable to use audtool, as root or with sudo, to get the state of audacious run by a specific user - Added by John Lindgren about 10 years ago

audtool uses D-Bus, so you need $DBUS_SESSION_BUS_ADDRESS set. Here is a script that worked for me:

#!/bin/sh

pid=`pidof audacious`
user=`ps -p $pid -o user=`
export `strings /proc/$pid/environ | grep DBUS_SESSION_BUS_ADDRESS`
sudo -E -u $user audtool "$@" 

    (1-1/1)