You are not logged in.

#1 2013-02-11 19:12:31

mityukov
Member
Registered: 2010-10-10
Posts: 66

[SOLVED] Suspend KTorrent when AC is unplugged (DBus question)

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

#2 2013-02-11 20:00:57

lucke
Member
From: Poland
Registered: 2004-11-30
Posts: 4,018

Re: [SOLVED] Suspend KTorrent when AC is unplugged (DBus question)

su lucke -c "qdbus org.ktorrent.ktorrent /core setSuspended true" works here; it fails with your error when ktorrent isn't running.

Offline

#3 2013-02-11 20:47:33

mityukov
Member
Registered: 2010-10-10
Posts: 66

Re: [SOLVED] Suspend KTorrent when AC is unplugged (DBus question)

lucke wrote:

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

#4 2013-02-11 21:05:58

lucke
Member
From: Poland
Registered: 2004-11-30
Posts: 4,018

Re: [SOLVED] Suspend KTorrent when AC is unplugged (DBus question)

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

#5 2013-02-12 08:51:09

mityukov
Member
Registered: 2010-10-10
Posts: 66

Re: [SOLVED] Suspend KTorrent when AC is unplugged (DBus question)

lucke wrote:

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

Board footer

Powered by FluxBB