View previous topic :: View next topic |
Author |
Message |
Xander314 n00b
Joined: 16 Apr 2012 Posts: 61
|
Posted: Sat Mar 01, 2014 1:43 pm Post subject: Using Environment Variables in Openbox Keybindings |
|
|
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 |
|
|
BitJam Advocate
Joined: 12 Aug 2003 Posts: 2508 Location: Silver City, NM
|
Posted: Sat Mar 08, 2014 1:47 am Post subject: |
|
|
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 |
|
|
braydenjw n00b
Joined: 03 Oct 2017 Posts: 1
|
Posted: Tue Oct 03, 2017 1:47 am Post subject: |
|
|
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 |
|
|
Juippisi Developer
Joined: 30 Sep 2005 Posts: 724 Location: /home
|
Posted: Tue Oct 03, 2017 5:21 am Post subject: |
|
|
^ 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 |
|
|
|