You are not logged in.

#1 2012-04-22 16:35:48

Gumper
Member
From: U.S.A.
Registered: 2009-10-26
Posts: 132

Script not working correctly when launched from Openbox

I have the following script that I'm trying to run from Openbox that tells me if my cap lock or numb lock is on or off. When I run this from the cli it works correctly, but if launched from my keybindings in Openbox it is always telling me that the numb lock or cap lock is on.

!/bin/bash
#used to send message to desktop when
#caps lock and num lock are on 
#must have libnotify installed or
#xfce4-notifyd if using xfce


#set path to icons
caps_on_icon=/home/gumper/Bin/icons/capslock-on.xpm
caps_off_icon=/home/gumper/Bin/icons/capslock-off.xpm
numbs_on_icon=/home/gumper/Bin/icons/numlock-on.xpm
numbs_off_icon=/home/gumper/Bin/icons/numlock-off.xpm


#check to see if caps or nums are on or off
status=`xset q | grep LED | cut -d ':' -f4`

#check which pressed key is calling script by checking 
#argument sent to script
key_press=$1


if   [$status = 00000000 ]; then	
     status=both_off
elif [$status = 00000001 ]; then	
     status=caps_on
elif [$status = 00000002 ]; then	
     status=numbs_on
elif [$status = 00000003 ]; then	
     status=both_on
else status=error
fi		

case "$key_press" in
	cap_lock)	
		case "$status" in
			both_off) notify-send "Caps lock" "   OFF " -i $caps_off_icon &;;
			caps_on ) notify-send "Caps lock" "   ON "  -i $caps_on_icon  &;;
			both_on ) notify-send "Caps lock" "   ON "  -i $caps_on_icon  &;;
			numbs_on) notify-send "Caps lock" "   OFF " -i $caps_off_icon &;;
			error	) notify-send "Shut'er down clancy"		      &;;	
		esac ;;
	numb_lock)
		case "$status" in
			both_off) notify-send "Num lock" "    OFF " -i $numbs_off_icon &;;
			caps_on ) notify-send "Num lock" "    OFF " -i $numbs_off_icon &;;
			both_on ) notify-send "Num lock" "    ON  " -i $numbs_on_icon  &;;
			numbs_on) notify-send "Num lock" "    ON  " -i $numbs_on_icon  &;;
			error	) notify-send "Shut'er down clancy"		       &;;
		esac
	esac

exit 0

The keybindings that I'm using in Openbox are as follows:

<keybind key="Num_Lock">
      <action name="Execute">
        <command>sh ~/Bin/notify-send_cap_message.sh numb_lock</command>
      </action>
    </keybind>
    <keybind key="Caps_Lock"> 
      <action name="Execute">
        <command>sh ~/Bin/notify-send_cap_message.sh cap_lock</command>
      </action>
    </keybind> 

I'm assuming that it has something to do with "xset" but I'm not sure what.

Any ideas on why this doesn't work correctly when called from Openbox?


Ready yourselves, ready yourselves
Let us shine the light of Jesus in the darkest night
Ready yourselves, ready yourselves
May the powers of darkness tremble as our praises rise .... Casting Crowns-Until The Whole World Hears.

Offline

#2 2012-04-22 17:04:51

swanson
Member
From: Sweden
Registered: 2011-02-05
Posts: 759

Re: Script not working correctly when launched from Openbox

I'm no guru at all, but i'd look into this;

status=`xset q | grep LED | cut -d ':' -f4`

And change it to;

status=$(xset q | grep LED | cut -d ':' -f4)

In short, brackets instead of those sinlge qoutes back ticks. (I knew that)

Last edited by swanson (2012-04-22 18:43:36)

Offline

#3 2012-04-22 17:35:56

Gumper
Member
From: U.S.A.
Registered: 2009-10-26
Posts: 132

Re: Script not working correctly when launched from Openbox

swanson wrote:

I'm no guru at all, but i'd look into this;

status=`xset q | grep LED | cut -d ':' -f4`

And change it to;

status=$(xset q | grep LED | cut -d ':' -f4)

In short, brackets instead of those sinlge qoutes.

Just tried your suggestion and I have the same results.

Thanks though.


Ready yourselves, ready yourselves
Let us shine the light of Jesus in the darkest night
Ready yourselves, ready yourselves
May the powers of darkness tremble as our praises rise .... Casting Crowns-Until The Whole World Hears.

Offline

#4 2012-04-22 17:45:12

dodo3773
Member
Registered: 2011-03-17
Posts: 820

Re: Script not working correctly when launched from Openbox

swanson wrote:

In short, brackets instead of those sinlge qoutes.

Those look like back ticks to me. Not single quotes. Not that your suggestion is wrong though. Would probably be worth looking into actually. What catches my eye is this:

 <command>sh ~/Bin/notify-send_cap_message.sh cap_lock</command>

Maybe openbox is not expanding "~". Also, maybe you can try (as long as your script has executable permissions (I am sure it probably does just wanted to throw that in there)) just calling the full path of the script without sh . Nevermind I call bash in mine and it works fine. I do put the full path in though (bash /home/username/path/to/script.sh).

Offline

#5 2012-04-22 18:22:55

Gumper
Member
From: U.S.A.
Registered: 2009-10-26
Posts: 132

Re: Script not working correctly when launched from Openbox

Ok, I have another piece to the puzzle. If I add this:

sleep 1

before the "xset" command, then it works ok. So it must be a timing issue somewhere?


Ready yourselves, ready yourselves
Let us shine the light of Jesus in the darkest night
Ready yourselves, ready yourselves
May the powers of darkness tremble as our praises rise .... Casting Crowns-Until The Whole World Hears.

Offline

#6 2012-04-22 18:30:45

dodo3773
Member
Registered: 2011-03-17
Posts: 820

Re: Script not working correctly when launched from Openbox

Gumper wrote:

Ok, I have another piece to the puzzle. If I add this:

sleep 1

before the "xset" command, then it works ok. So it must be a timing issue somewhere?

Are you adding it to the script itself or to the openbox keybind command?

Offline

#7 2012-04-22 18:59:10

Gumper
Member
From: U.S.A.
Registered: 2009-10-26
Posts: 132

Re: Script not working correctly when launched from Openbox

dodo3773 wrote:
Gumper wrote:

Ok, I have another piece to the puzzle. If I add this:

sleep 1

before the "xset" command, then it works ok. So it must be a timing issue somewhere?

Are you adding it to the script itself or to the openbox keybind command?

I'm adding it to the script right before the "xset" command is called.

Last edited by Gumper (2012-04-22 18:59:40)


Ready yourselves, ready yourselves
Let us shine the light of Jesus in the darkest night
Ready yourselves, ready yourselves
May the powers of darkness tremble as our praises rise .... Casting Crowns-Until The Whole World Hears.

Offline

Board footer

Powered by FluxBB