Gentoo Forums
Gentoo Forums
Gentoo Forums
Quick Search: in
Using Environment Variables in Openbox Keybindings
View unanswered posts
View posts from last 24 hours
View posts from last 7 days

 
Reply to topic    Gentoo Forums Forum Index Desktop Environments
View previous topic :: View next topic  
Author Message
Xander314
n00b
n00b


Joined: 16 Apr 2012
Posts: 61

PostPosted: Sat Mar 01, 2014 1:43 pm    Post subject: Using Environment Variables in Openbox Keybindings Reply with quote

I am setting up keybindings for openbox, several of which will run Chrome (browser as well as mail, calendar etc as webapps). But down the line I might want to change my browser, so I tried setting a BROWSER environment variable and then putting this in rc.xml:
Code:

<keybind ...>
  <action name="Execute">
    <command>$BROWSER</command>
  </action>
</keybind>


But Openbox complains at this, saying that it can't execute the command "$BROWSER". I have checked that the variable is non empty, so it seems the problem is that OpenBox doesn't accept environment variables in keybind commands. Is there some way I can make Openbox interpret the environment variable correctly?

EDIT: I'm using the following workaround, but surely there's a better way...
Code:

<keybind ...>
  <action name="Execute">
    <command>~/bin/env-launch.sh "BROWSER"</command>
  </action>
</keybind>

env-launch.sh:
Code:

eval command=\$$1
$command
Back to top
View user's profile Send private message
BitJam
Advocate
Advocate


Joined: 12 Aug 2003
Posts: 2508
Location: Silver City, NM

PostPosted: Sat Mar 08, 2014 1:47 am    Post subject: Reply with quote

This post suggests you set the environment variables in ~/.config/openbox/environment. I don't know if this will work for you and if it does work I don't know if it will solve your problem.
Back to top
View user's profile Send private message
braydenjw
n00b
n00b


Joined: 03 Oct 2017
Posts: 1

PostPosted: Tue Oct 03, 2017 1:47 am    Post subject: Reply with quote

Sorry to resurrect and old post, but this was the first result on Google when searching for this problem.

It's true that environment variables won't work in Openbox's XML configuration files (like rc.xml and menu.xml). You can invoke scripts and use environment variables inside those scripts, but it's unfortunate that you must get a third file involved.

A pseudo-work-around is to use aliases instead of environment variables. As an example, in Openbox's environment file (~/.config/openbox/environment), I defined this alias:
Code:
alias volumectl="pactl set-sink-volume $(pactl list short | grep RUNNING | sed -e 's,^\([0-9][0-9]*\)[^0-9].*,\1,')"

...and now from within rc.xml I can use the commands "volumectl +1%" and "volumectl -1%" to change the volume on the active sink.

So if you can re-think your problem in a way that can use aliases instead of environment variables, you can achieve the same behaviour.

For this particular user, they could define "alias browser=firefox" in the environment file (or whichever browser they wish to run) and just use the "browser" command in rc.xml.
Back to top
View user's profile Send private message
Juippisi
Developer
Developer


Joined: 30 Sep 2005
Posts: 724
Location: /home

PostPosted: Tue Oct 03, 2017 5:21 am    Post subject: Reply with quote

^ Thats pretty much how I dealt with it as well. Made few .sh files in my ~/bin directory and called those from rc.conf.

But changing your default browser in rc.conf is just one line of sed anyway...

Something like
Code:
sed -i 's/chromium/firefox/g' rc.conf
Back to top
View user's profile Send private message
Display posts from previous:   
Reply to topic    Gentoo Forums Forum Index Desktop Environments All times are GMT
Page 1 of 1

 
Jump to:  
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum