You are not logged in.

#1 2010-09-02 19:33:07

dameunmate
Member
From: London
Registered: 2010-01-19
Posts: 85
Website

[SOLVED] rc.xml: & ampersand and # hash break Openbox keybinding URL's

I'm trying to get a keybinding to work in Openbox's rc.xml, so that when I press W-XF86Mail it opens a Google documents spreadsheet.

rc.xml:

  <keybind key="W-XF86Mail">
    <action name="Execute">
     <execute>firefox https://spreadsheets.google.com/ccc?key=0AjuCrdYnTCyacGNfX0FuRzBFUnBOalNxS0VXYjJhVUE&hl=en#gid=3</execute>
    </action>
  </keybind>

Other keybindings in the same file work fine. But when I reconfigure Openbox I get an error message "One or more XML syntax errors were found while parsing the Openbox configutation files...". After reconfiguration, I press W-XF86Mail and it starts Firefox but opens the wrong URL - the first bit is correct but the last bit reads ...key=0AjuCrdYnTCyacGNfX0FuRzBFUnBOalNxS0VXYjJhVUE=en instead. As you can see the last bit &hl=en#gid=3 is missing. If I delete the & ampersand then the hash # character seems to cause the same problem. Is there a problem with using the ampersand  or hash characters in keybindings?

Last edited by dameunmate (2010-09-04 14:24:50)

Offline

#2 2010-09-02 19:44:44

jasonwryan
Anarchist
From: .nz
Registered: 2009-05-09
Posts: 28,135
Website

Re: [SOLVED] rc.xml: & ampersand and # hash break Openbox keybinding URL's

Have you tried escaping the ampersand?


Arch + dwm   •   Mercurial repos  •   Surfraw

Registered Linux User #482438

Offline

#3 2010-09-02 19:58:58

karol
Archivist
Registered: 2009-05-06
Posts: 25,440

Re: [SOLVED] rc.xml: & ampersand and # hash break Openbox keybinding URL's

You can put 'firefox URL' into a script.

Offline

#4 2010-09-02 20:23:53

dameunmate
Member
From: London
Registered: 2010-01-19
Posts: 85
Website

Re: [SOLVED] rc.xml: & ampersand and # hash break Openbox keybinding URL's

thank for the replies!

how do I escape the ampersand?

and how do I create a script? hmmm.. I should check the WIKI...

Offline

#5 2010-09-02 20:27:53

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

Re: [SOLVED] rc.xml: & ampersand and # hash break Openbox keybinding URL's

You don't even need a script, just a function in your bashrc would do. It's cleaner than a script as well.

First hit on google for linux escape character.


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

Offline

#6 2010-09-02 20:30:09

karol
Archivist
Registered: 2009-05-06
Posts: 25,440

Re: [SOLVED] rc.xml: & ampersand and # hash break Openbox keybinding URL's

.:B:. wrote:

You don't even need a script, just a function in your bashrc would do. It's cleaner than a script as well.

Can you integrate it in the current scheme: openbox keybinding?

Offline

#7 2010-09-02 20:32:45

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

Re: [SOLVED] rc.xml: & ampersand and # hash break Openbox keybinding URL's

As far as i know yes, it just acts like any command (be it script or binary) that's in your $PATH, except that it doesn't need to be in there. It's a bit like a bash builtin.


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

Offline

#8 2010-09-02 20:36:52

dameunmate
Member
From: London
Registered: 2010-01-19
Posts: 85
Website

Re: [SOLVED] rc.xml: & ampersand and # hash break Openbox keybinding URL's

thanks. I'm new to Linux, not familiar so looking up .bashrc now...

Last edited by dameunmate (2010-09-02 20:48:30)

Offline

#9 2010-09-02 20:48:10

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

Re: [SOLVED] rc.xml: & ampersand and # hash break Openbox keybinding URL's

~/.bashrc wink

This is how your function could look:

gdocspread() {

firefox https://spreadsheets.google.com/ccc?key=0AjuCrdYnTCyacGNfX0FuRzBFUnBOalNxS0VXYjJhVUE&hl=en#gid=3

}

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

Offline

#10 2010-09-02 20:50:36

karol
Archivist
Registered: 2009-05-06
Posts: 25,440

Re: [SOLVED] rc.xml: & ampersand and # hash break Openbox keybinding URL's

And if I understand correctly, you put it's name (gdocspread) between the <execute> tags:

<keybind key="W-XF86Mail">
    <action name="Execute">
     <execute>gdocspread</execute>
    </action>
  </keybind>

Offline

#11 2010-09-02 21:02:33

dameunmate
Member
From: London
Registered: 2010-01-19
Posts: 85
Website

Re: [SOLVED] rc.xml: & ampersand and # hash break Openbox keybinding URL's

thank you that's very kind of you to write the code for me.

I've tried the above but I press the keys and now nothing happens, firefox does't even start. Here's my entire /home/username/.bashrc:

# Check for an interactive session
[ -z "$PS1" ] && return

alias ls='ls --color=auto'
PS1='[\u@\h \W]\$ '

gdocspread() {

firefox https://spreadsheets.google.com/ccc?key=0AjuCrdYnTCyacGNfX0FuRzBFUnBOalNxS0VXYjJhVUE&hl=en#gid=3

}

I noticed there's another .bashrc at ./etc/skel/.bashrc - should I be putting the code here instead?

And here's the keybinding in openbox/rc.xml:

  <keybind key="W-XF86Mail">
    <action name="Execute">
     <execute>gdocspread</execute>
    </action>
  </keybind>

Offline

#12 2010-09-02 21:06:32

karol
Archivist
Registered: 2009-05-06
Posts: 25,440

Re: [SOLVED] rc.xml: & ampersand and # hash break Openbox keybinding URL's

/etc/skel/.bashrc is a "skeleton file" (something like a template) - you don't touch it. If you want to start anew, _copy_ that file an modify _the copy_

Run

. /home/username/.bashrc

and try again.

Offline

#13 2010-09-02 21:26:01

dameunmate
Member
From: London
Registered: 2010-01-19
Posts: 85
Website

Re: [SOLVED] rc.xml: & ampersand and # hash break Openbox keybinding URL's

thanks, yes I'm editing /home/username/.bashrc but still no luck (see above)

Offline

#14 2010-09-02 21:42:24

karol
Archivist
Registered: 2009-05-06
Posts: 25,440

Re: [SOLVED] rc.xml: & ampersand and # hash break Openbox keybinding URL's

An what happens if you run

gdocspread

from the terminal?

Offline

#15 2010-09-02 21:59:40

Inxsible
Forum Fellow
From: Chicago
Registered: 2008-06-09
Posts: 9,130

Re: [SOLVED] rc.xml: & ampersand and # hash break Openbox keybinding URL's

you would most likely need the command to be (if you use urxvt i.e.)

<keybind key="W-XF86Mail">
    <action name="Execute">
    <execute>urxvt -e gdocspread</execute>
    </action>
</keybind>

but that would mean that it would also spawn a terminal instance. You can avoid that by using the urxvt daemon though. OR go back to escaping the & and # in the command.


Forum Rules

There's no such thing as a stupid question, but there sure are a lot of inquisitive idiots !

Offline

#16 2010-09-02 22:12:41

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

Re: [SOLVED] rc.xml: & ampersand and # hash break Openbox keybinding URL's

Calling it with a terminal emulator shouldn't be necessary.

You need to source the .bashrc file before you can use the new function.

Edit: I obviously missed that.


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

Offline

#17 2010-09-02 22:14:32

dameunmate
Member
From: London
Registered: 2010-01-19
Posts: 85
Website

Re: [SOLVED] rc.xml: & ampersand and # hash break Openbox keybinding URL's

Yes I do use urxvt so I've just tried that, and no error messages but after reconfiguring, when I hit the keys I get nothing. But the screen flickers almost as though urxvt opens but the command does nothing and it closes again?

Offline

#18 2010-09-02 22:14:40

karol
Archivist
Registered: 2009-05-06
Posts: 25,440

Re: [SOLVED] rc.xml: & ampersand and # hash break Openbox keybinding URL's

.:B:. wrote:

You need to source the .bashrc file before you can use the new function.

https://bbs.archlinux.org/viewtopic.php … 24#p820224
If OP can't run the command from a terminal, something is definitely wrong.

Offline

#19 2010-09-02 22:15:58

karol
Archivist
Registered: 2009-05-06
Posts: 25,440

Re: [SOLVED] rc.xml: & ampersand and # hash break Openbox keybinding URL's

dameunmate wrote:

Yes I do use urxvt so I've just tried that, and no error messages but after reconfiguring, when I hit the keys I get nothing. But the screen flickers almost as though urxvt opens but the command does nothing and it closes again?

And what happens, if you open urxvt and run gdocspread? Type "gdocspread" (but without the quotes).

Offline

#20 2010-09-03 04:41:07

jasonwryan
Anarchist
From: .nz
Registered: 2009-05-09
Posts: 28,135
Website

Re: [SOLVED] rc.xml: & ampersand and # hash break Openbox keybinding URL's

jasonwryan wrote:

Have you tried escaping the ampersand?

Sorry to repeat myself, but it seems that this would be the simplest approach - either in terms of getting it to work, or ruling out the obvious...


Arch + dwm   •   Mercurial repos  •   Surfraw

Registered Linux User #482438

Offline

#21 2010-09-03 05:09:03

hbekel
Member
Registered: 2008-10-04
Posts: 311

Re: [SOLVED] rc.xml: & ampersand and # hash break Openbox keybinding URL's

@B: openbox will just exec() a command, just like urxvt -e. If you need a shell command, you'd have to use

<execute>sh -c 'command'</execute> or
<execute>bash -c 'command'</execute>

But that won't source your .bashrc since it's not an interactive session. (and forget about -i, that'll just freeze openbox wink ).

@dameunmate: Just use "&amp;" instead of a plain "&". It's the way you write and ampersand in html or xml. Google 'html entities' if openbox complains about other characters in a similar manner.

Last edited by hbekel (2010-09-03 05:11:43)

Offline

#22 2010-09-03 09:04:47

dameunmate
Member
From: London
Registered: 2010-01-19
Posts: 85
Website

Re: [SOLVED] rc.xml: & ampersand and # hash break Openbox keybinding URL's

thanks for the tips, I've now got the right page to load when I type the command into the urxvt terminal. But it still doesn't work with Openbox keybindings, I edit and reconfigure but press the keys and get no response at all. I've checked and the same keybinding will successfully open other programs and webpages. Here's the keybinding in /home/username/.config/openbox/rc.xml:

<keybind key="W-XF86Mail">
    <action name="Execute">
    <execute>urxvt -e gdocspread</execute>
    </action>
</keybind>

I've also tried <execute>urxvt -c gdocspread</execute> and simply <execute>gdocspread</execute> to no avail. However changing the same keybinding command to <execute>urxvt</execute> does open urxvt successfuly.

So the keybinding will open urxvt, and if I manually open a urxvt terminal and type gdocspread firefox starts on my desired web page. So what's the missing link?


NB: About the ampersand:
For some reason even from the terminal it won't work with the ampersand, but I discovered that I can leave that out as it just defines the language. However for future reference it would be useful to know how to put an ampersand in a URL. This is the code that does load the correct page
:

home/username/.bashrc

# Check for an interactive session
[ -z "$PS1" ] && return

alias ls='ls --color=auto'
PS1='[\u@\h \W]\$ '

gdocspread() {

firefox https://spreadsheets.google.com/ccc?key=0AjuCrdYnTCyacGNfX0FuRzBFUnBOalNxS0VXYjJhVUE&amp;hl=en#gid=3

}

Interestingly the URL etc...key=0AjuCrdYnTCyacGNfX0FuRzBFUnBOalNxS0VXYjJhVUE&hl=en#gid=3 and the URL etc...key=0AjuCrdYnTCyacGNfX0FuRzBFUnBOalNxS0VXYjJhVUE&amp;hl=en#gid=3 won't load, the URL gets cut off at the ampersand.

Furthermore it's interesting to note that in the above configuration file /home/username/.bashrc only the ampersand causes problems, but in /home/username/openbox/rc.xml both the ampersand and the hash characters cause the URL to be cut off.

Offline

#23 2010-09-03 09:38:40

Ramses de Norre
Member
From: Leuven - Belgium
Registered: 2007-03-27
Posts: 1,289

Re: [SOLVED] rc.xml: & ampersand and # hash break Openbox keybinding URL's

1) I don't think openbox sources your bashrc, that's why you can't call the function from a keybind.

2) As said before you'll have to use html entities in the url for xml files _or_ quote the string containing special characters (&, #, ?, ...) in bash.

So either you use this directly in rc.xml

https://spreadsheets.google.com/ccc?key=0AjuCrdYnTCyacGNfX0FuRzBFUnBOalNxS0VXYjJhVUE&amp;hl=en#gid=3

or you use this in bash and put the whole thing in a file on your PATH instead of a function in bashrc

"https://spreadsheets.google.com/ccc?key=0AjuCrdYnTCyacGNfX0FuRzBFUnBOalNxS0VXYjJhVUE&amp;hl=en#gid=3"

The way you've put the thing in bashrc, the # is interpreted as the beginning of a comment, which should have been obvious by the syntax highlighting.

Offline

#24 2010-09-03 14:50:25

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

Re: [SOLVED] rc.xml: & ampersand and # hash break Openbox keybinding URL's

hbekel wrote:

@B: openbox will just exec() a command, just like urxvt -e. If you need a shell command, you'd have to use

<execute>sh -c 'command'</execute> or
<execute>bash -c 'command'</execute>

But that won't source your .bashrc since it's not an interactive session. (and forget about -i, that'll just freeze openbox wink ).

And it looked so promising...

I guess that shows the limits of my knowledge tongue.


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

Offline

#25 2010-09-03 15:45:25

brisbin33
Member
From: boston, ma
Registered: 2008-07-24
Posts: 1,796
Website

Re: [SOLVED] rc.xml: & ampersand and # hash break Openbox keybinding URL's

hbekel wrote:

@B: openbox will just exec() a command, just like urxvt -e. If you need a shell command, you'd have to use

<execute>sh -c 'command'</execute> or
<execute>bash -c 'command'</execute>

But that won't source your .bashrc since it's not an interactive session. (and forget about -i, that'll just freeze openbox wink ).

IIRC, bash -l will initiate a login shell which includes all of the bashrc goodness.

Offline

Board footer

Powered by FluxBB