You are not logged in.
Here's the working scripts:
~/.kde4/Autostart/dbus_export.sh
echo $DBUS_SESSION_BUS_ADDRESS > ~/.dbus_session
~/bin/suspent_ktorrent.sh
#!/bin/sh
DBUS=$(ps aux | grep 'dbus-launch' | grep -v root)
if [[ ! -z $DBUS ]];then
USER=$(echo $DBUS | awk '{print $1}')
USERHOME=$(getent passwd $USER | cut -d: -f6)
export XAUTHORITY="$USERHOME/.Xauthority"
for x in /tmp/.X11-unix/*; do
DISPLAYNUM=$(echo $x | sed s#/tmp/.X11-unix/X##)
if [[ -f "$XAUTHORITY" ]]; then
export DISPLAY=":$DISPLAYNUM"
fi
done
else
USER=<YOUR USERNAME>
USERHOME=<PATH TO YOUR HOME>
export XAUTHORITY="$USERHOME/.Xauthority"
export DISPLAY=":0"
fi
# the following line is what I missed!
export DBUS_SESSION_BUS_ADDRESS=`cat $USERHOME/.dbus_session`
case "$1" in
yes|true|on|1)
su $USER -c "qdbus org.ktorrent.ktorrent /core setSuspended true" &
;;
no|false|off|0)
su $USER -c "qdbus org.ktorrent.ktorrent /core setSuspended false" &
;;
*) exit $NA
;;
esac
Now, it is possible to call `/home/USER/bin/suspent_ktorrent.sh [on|off]` from within system scripts (like powerdown/powerup) to have KTorrent suspended/resumed.
--- 8< ---
Hi, I'm trying to setup powerdown script to suspend KTorrent.
Here's the command that works just well when I'm running it from within the user session:
$ qdbus org.ktorrent.ktorrent /core setSuspended false
The powerdown script is running under the root, however, so, I'd like to know how to send DBus message to the user session's DBus.
At the moment, I have the following test script:
USER=pilat
USERHOME=/home/pilat
export XAUTHORITY="$USERHOME/.Xauthority"
export DISPLAY=":0"
su $USER -c "qdbus org.ktorrent.ktorrent /core setSuspended true &
when I run it from root, I get the following error:
Cannot find 'setSuspended' in object /core at org.ktorrent.ktorrent
There might be a need to pass $DBUS_SESSION_BUS_ADDRESS value to the qdbus. Is there a way I can read environment variable name from a running user session (being root myself)?
Last edited by mityukov (2013-02-12 08:57:41)
Offline
su lucke -c "qdbus org.ktorrent.ktorrent /core setSuspended true" works here; it fails with your error when ktorrent isn't running.
Offline
su lucke -c "qdbus org.ktorrent.ktorrent /core setSuspended true" works here; it fails with your error when ktorrent isn't running.
Have you gone root before trying this command?
Anyway, I have KTorrent running (and the qdbus command under the user works here), but still get the issue.
Offline
I ran it as root. And I'm using that command on suspend/resume. If you want to play with $DBUS_SESSION_BUS_ADDRESS, see https://bbs.archlinux.org/viewtopic.php … 6#p1160336
Offline
If you want to play with $DBUS_SESSION_BUS_ADDRESS, see https://bbs.archlinux.org/viewtopic.php … 6#p1160336
Thank you. It worked for me!
Offline