4

Question:

I'm using i3-wm and I have Mod3 working as a hotkey. I have the following in ./config/i3/config:

#This command works
  bindsym Mod3+f exec "firefox" 

#This doesn't work nor do my other scripts
  bindsym Mod3+w exec "openBrowser" 

Both of these commands work fine when I run them from bash but only the 'firefox' command runs with the hotkey. Running my own script doesn't work.

Additional Details:

openBrowser is a script in /opt/bin/ which is in my path. Also tried doing:

#This command works
  bindsym Mod3+f exec /opt/bin/openBrowser

I've also tried other scripts none of which work when invoked by i3. Thus I've determined it's not an issue with the script.

I also noticed when I'm in bash if I do Mod3+w my cursor blinks, where as if I do Mod3+[any unset key] the key writes it's value to the screen. So it seems i3 is at least trying to run the function.

Philip Kirkbride
  • 9,816
  • 25
  • 95
  • 167
  • You have `openBrowser` in your config but also tried `/opt/bin/openbrowser`. So how the file is actually called? Case matters. Also, do you have any relative paths in that script? i3 runs it from other directory than your script is located in. This could also be a reason. Try to start the script from the directory where i3 config is located. – ddnomad Oct 23 '16 at 15:20
  • Just a typo the second time, I used openBrowser which is the correct naming. – Philip Kirkbride Oct 23 '16 at 15:35
  • Try to execute it from the console in a folder where i3 config is located. It should reveal errors if any – ddnomad Oct 23 '16 at 15:37
  • @ddnomad as I mentioned in the text both commands work fine when I run them from bash. – Philip Kirkbride Oct 23 '16 at 15:39
  • Can you add a source of a script to your question? I guess you're trying to open a Tor browser using an i3 shortcut? – ddnomad Oct 23 '16 at 15:40
  • @ddnomad question updated; no just picking a random site, but I also want to make it easy to switch to chromium or another browser while keeping the same startup settings. – Philip Kirkbride Oct 23 '16 at 15:43
  • I tried the same but with Mod4+f and it works (except the fact that it only opens the firefox). My `xmodmap` has no set mod3, did you set it by hand? – ddnomad Oct 23 '16 at 15:51
  • @ddnomad yes I replaced caps lock with hyper-key using this answer http://unix.stackexchange.com/a/151046/16792 (and it's working fine for Mod3+f ) – Philip Kirkbride Oct 23 '16 at 15:53
  • Try to remove doublequotes from the script name. i3 throws me an error if I add them. So kinda like that: `bindsym Mod3+f exec openBrowser`. If it won't work out try the absolute path. – ddnomad Oct 23 '16 at 15:58
  • @ddnomad thx but no luck with either changes. It's weird that you're getting an error and I'm not though. When/where does the error show? I tried Mod3+r exec "reboot -n" and that works. – Philip Kirkbride Oct 23 '16 at 16:01
  • It throws the red bar at the top of the screen stating that the command can't be executed. It's indeed weird. – ddnomad Oct 23 '16 at 16:03
  • Do your scripts have at least 755 permissions? i3 probably has its own user that the desktop runs under and uses to call commands. Since you are able to run the script normally, and system-installed packages work through the shortcut, it sounds like a permissions issue to me. – Thegs Aug 31 '17 at 13:32
  • @Thegs yes permissions of 755 – Philip Kirkbride Aug 31 '17 at 13:39
  • @PhilipKirkbride Do you know where your `i3` output is going to? I'd have a look at that and see if there is any error printed when you try that key combination. What kind of scripts is this? (Which scripting language?) – njsg Sep 01 '17 at 08:11
  • @Thegs here `i3` does not run under a separate user, and I doubt such a thing would be practical — after all, the window manager needs to start applications for the user which is using it, and it would be harder/more complicated to do so if it were running under a separate, unrelated user. – njsg Sep 01 '17 at 08:14

2 Answers2

6

I attempted to duplicate the issue you describe. What I found is that I had two i3 config files existing at the same time. ~/.config/i3/config and ~/.i3/config.

In my case, editing ~/.config/i3/config had no effect because it seems that ~/.i3/config trumps it.

It's a long shot, but see if maybe you have more than one config file, and possibly you are editing the wrong one.

Philip Kirkbride
  • 9,816
  • 25
  • 95
  • 167
Emile Mercier
  • 316
  • 2
  • 4
  • This is not the case for me because I added the `exec "firefox"` command in the same file and it loaded no problem. So I'm sure the config file loads. – Philip Kirkbride Sep 01 '17 at 12:32
  • Maybe try this: bindsym Mod3+f exec set > /tmp/set.out and have a look at the PATH, to see if it is what you expect. – Emile Mercier Sep 01 '17 at 13:08
  • nvm it was the case that I had 2 config files like you. I was able to figure some other stuff out with `Mod3+f exec set > /tmp/set.out`. Thanks. – Philip Kirkbride Sep 01 '17 at 13:17
3

The exec command starts an application by passing the command you specify to a shell. This implies that your programs will be searched in your $PATH. The default $PATH usually does not include /opt/bin, for example my is:

andreatsh@debian:~ 11:28 > echo $PATH
/usr/local/bin:/usr/bin:/bin:/usr/local/games:/usr/games

Try adding /opt/bin to your path, put in your ~/.bashrc:

export PATH=$PATH:/opt

I did some tests and this solves the problem for me. Now:

bindsym Mod3+w exec somescript
bindsym Mod3+w exec /opt/bin/somescript

have the same behavior and the script works.

andreatsh
  • 1,985
  • 1
  • 14
  • 15
  • thanks for trying but I already addressed the possibility of a path issue in my question text. – Philip Kirkbride Oct 28 '16 at 15:21
  • @PhilipKirkbride The default config has `bindsym Mod3+w layout tabbed`, maybe there is a conflict caused by `binsym Mod3+w exec "openBrowser"`, or this last `bindsym` is overwritten by the first? – andreatsh Oct 28 '16 at 17:07
  • you mean it has 'bindsym Mod+w layout tabbed' it doesn't reference mod3, and mod refers to windows or alt key. I also tried other letters so I can rule that out. – Philip Kirkbride Oct 28 '16 at 17:27
  • 1
    Have you tried to enable i3 logging? Maybe you could get some useful error messages, or it could be a bug of your release version. – andreatsh Oct 28 '16 at 18:55