You are not logged in.

#1 2011-09-08 08:37:45

lunyx
Member
From: Berlin
Registered: 2011-07-17
Posts: 21

Run script on resume

I want to have run a script after resume from hibernation in order to set my wacom tablet.

What is the appropriate way to do this?

I looked into https://wiki.archlinux.org/index.php/Pm-utils but couldn't find a solution.

Using Gnome 3.

Last edited by lunyx (2011-09-10 06:15:00)

Offline

#2 2011-09-08 09:16:24

Shadow256
Member
Registered: 2009-05-14
Posts: 18

Offline

#3 2011-09-08 09:50:29

lunyx
Member
From: Berlin
Registered: 2011-07-17
Posts: 21

Re: Run script on resume

I have seen this, but the hooks obviously apply system wide. Per user settings seem to be not possible.

Offline

#4 2011-09-08 10:16:19

.:B:.
Forum Fellow
Registered: 2006-11-26
Posts: 5,819
Website

Re: Run script on resume

You can script something that checks whether a user is logged on and only execute then. Suspend/resume actions are system-wide.


Got Leenucks? :: Arch: Power in simplicity :: Get Counted! Registered Linux User #392717 :: Blog thingy

Offline

#5 2011-09-10 06:14:34

lunyx
Member
From: Berlin
Registered: 2011-07-17
Posts: 21

Re: Run script on resume

Still a problem:

The script "setwacom" runs on resume but without effect. Starting the script manually works fine.

My hook:

#!/bin/bash

case "$1" in
    hibernate|suspend)
    ;;
    thaw|resume)
        export DISPLAY=0:0
        /home/my-user/bin/setwacom
    ;;
    *)
    ;;
esac

Has anybody any idea, why it isn't working?

Last edited by lunyx (2011-09-10 08:01:30)

Offline

#6 2011-09-10 07:41:47

lula
Member
Registered: 2009-07-16
Posts: 71

Re: Run script on resume

I think the problem is, that the hook runs as root and your trying to connect to the users desktop as root. Try something like

DISPLAY=:0 sudo -u your_user -H your_skript

Have a look at man sudo for details.

Offline

#7 2011-09-10 12:08:41

eldragon
Member
From: Buenos Aires
Registered: 2008-11-18
Posts: 1,029

Re: Run script on resume

check the environment settings for your script.

how does setwacom actually set wacom? dbus? you need the propper dbus session variables set up.

i used to have something like this for gconf and netcfg, but it stopped working due to a dbus update some time ago, and since i dont use a proxy anymore, never bothered to fix it...

here it is (example, you need to fix this, and its an ugly hack).

#!/bin/bash
PROXY=$1
PORT=$2
ON_USER=$(cat /etc/passwd | grep :1000: | cut -d ':' -f 1)

#Assumes user directory is /home/$ON_USER
# Picks up the running dbus session if there is one
export $(grep -v "^#" /home/$ON_USER/.dbus/session-bus/`cat /var/lib/dbus/machine-id`-0)

# if there is no dbus session running, start one
if sudo -u $ON_USER test -z "$DBUS_SESSION_BUS_ADDRESS" ; then
       eval `sudo -u $ON_USER dbus-launch --sh-syntax --exit-with-session`
fi

# some debugging info here, feel free to comment these out
echo $ON_USER
echo $DBUS_SESSION
echo $DBUS_SESSION_BUS_ADDRESS
echo $DBUS_SESSION_BUS_WINDOWID
echo $DBUS_SESSION_BUS_PID


if [ -n "$PROXY" ]; then
        sudo -u $ON_USER "DBUS_SESSION_BUS_ADDRESS="$DBUS_SESSION_BUS_ADDRESS gconftool-2 --type bool --set /system/http_proxy/use_http_proxy true
        sudo -u $ON_USER "DBUS_SESSION_BUS_ADDRESS="$DBUS_SESSION_BUS_ADDRESS gconftool-2 --type bool --set /system/http_proxy/use_same_proxy true
        sudo -u $ON_USER "DBUS_SESSION_BUS_ADDRESS="$DBUS_SESSION_BUS_ADDRESS gconftool-2 --type string --set /system/http_proxy/host "$PROXY"
        sudo -u $ON_USER "DBUS_SESSION_BUS_ADDRESS="$DBUS_SESSION_BUS_ADDRESS gconftool-2 --type int --set /system/http_proxy/port $PORT
                sudo -u $ON_USER "DBUS_SESSION_BUS_ADDRESS="$DBUS_SESSION_BUS_ADDRESS gconftool-2 --type string --set /system/proxy/mode "manual"
else
                sudo -u $ON_USER "DBUS_SESSION_BUS_ADDRESS="$DBUS_SESSION_BUS_ADDRESS "DBUS_SESSION_BUS_PID="$DBUS_SESSION_BUS_PID gconftool-2 --type string --set /system/proxy/mode "none"
        sudo -u $ON_USER "DBUS_SESSION_BUS_ADDRESS="$DBUS_SESSION_BUS_ADDRESS gconftool-2 --type bool --set /system/http_proxy/use_http_proxy false
fi

hope it helps

ps. if your script does not require dbus, it might be even easier,

Last edited by eldragon (2011-09-10 12:09:26)

Offline

#8 2011-09-10 12:42:25

lunyx
Member
From: Berlin
Registered: 2011-07-17
Posts: 21

Re: Run script on resume

My setwacom script looks like this:

#!/bin/bash

xsetwacom set "Wacom Bamboo Pen Pen stylus"  Threshold  12
xsetwacom set "Wacom Bamboo Pen Pen stylus"  Suppress   1
xsetwacom set "Wacom Bamboo Pen Pen stylus"  Rawsample  1
xsetwacom set "Wacom Bamboo Pen Pen stylus"  Rotate     Half

touch /home/my-user/bambooIsSet

The "touch" line changes the time stamp of bambooIsSet and shows, that the script in fact is executed but without any effect.

Very simple and no dbus involved. "xsetwacom" is delivered by the wacom tablet driver.

lula's proposal doesn't change anything.

Last edited by lunyx (2011-09-10 12:59:27)

Offline

#9 2011-09-10 22:52:41

lunyx
Member
From: Berlin
Registered: 2011-07-17
Posts: 21

Re: Run script on resume

When I open a terminal with Ctrl+Alt+F1 and try to execute a xsetwacom command, I get a error message "Invalid MIT-MAGIC-COOKIE-1 key ...".

As I understand it this means that the Xserver refuses the connection. Maybe that is what causes the above problem.

Is there a way to get the "valid MIT-MAGIC-COOKIE-1 key" in order to enable a connection? I found something related in the file .Xauthotity, but how to use it?

edit:

xauth list

delivers the MIT-MAGIC-COOKIE-1

Last edited by lunyx (2011-09-10 23:00:04)

Offline

#10 2011-09-11 15:31:17

lunyx
Member
From: Berlin
Registered: 2011-07-17
Posts: 21

Re: Run script on resume

With the following hook I get an error log after a resume:

#!/bin/bash

case "$1" in
    hibernate|suspend)
    ;;
    thaw|resume)
    DISPLAY=:0 sudo -u my-user xsetwacom set "Wacom Bamboo Pen Pen stylus" Rotate half &> /home/my-user/hook_log
    ;;
    *)
    ;;
esac

The error log shows:

Invalid MIT-MAGIC-COOKIE-1 keyFailed to open Display .

Obviously there is some kind of authentication needed. How to do that?

Last edited by lunyx (2011-09-11 15:37:03)

Offline

Board footer

Powered by FluxBB