How to link a custom keyboard shortcut to a bash script in Ubuntu 13.04?
First of all, aliases are not expanded in non-interactive shells. Read the ALIASES
section from man bash
in this sense. So, you can't use an alias in 'Command' field when you add/edit a custom shortcut.
Second, as geirha said in this comment, if you changed PATH
in .bashrc
file, that change will not be available in non-interactive shells. So, you need to change the PATH
in ~/.profile
file instead.
Third, if you still want to use only bldn
in 'Command' field when you add/edit a custom shortcut, you can rename your script with this name and add the script path to the PATH
in ~/.profile
file, as I said above.
Related videos on Youtube
mariotoss
Updated on September 18, 2022Comments
-
mariotoss over 1 year
As an Ubuntu 13.04 user I had myself as well various problems and incompatibilities with this newest version of Ubuntu. One of these is that the Brightness bar has suddenly disappeared from the 'System Settings --> Brightness & Lock' tab after I installed some packages (which I don't really remember what it was). I found out that a workaround is to use xbacklight.
As an exercise for myself, I wrote a short script in order to easily increase and decrease the brightness using xbacklight from terminal. The script is executable (has permission to execute), is an a directory that is included in $PATH in my .bashrc file and is linked to an alias ('blup' to increase and 'bldn' to decrease screen brightness). So, my two aliases (blup/bldn) work perfectly fine from a terminal line. Next, I wanted to link these to some keyboard shortcuts (for instance F2/F3). I did so in 'System Settings --> Keyboard --> Shortcuts --> Custom Shortcuts', but it did not work.
Why?
Furthermore, is there a way to 'discover' where and how other (non-custom) keyboard-shortcut commands are executed? For instance, the volume-up shortcut what terminal line does it execute, what alias is connected to (if any) and what directory are they put at (/usr/bin, something else...)?
As a newbie in script-writing I would appreciate any kind of help!
Thanks
P.S.1 Of course, simply one can paste the command 'xbacklight -inc/-dec 10' to the custom keyboard shortcuts and it will work fine. I just want to seize the opportunity and get to know a bit more about script writing and executing.
P.S.2 My problem is not the same as this one: How do I launch a bash script using a keyboard shortcut?, ie, I use no '~/' for '/home/user/'.
-
web.learner almost 11 yearsThis might help you askubuntu.com/questions/254424/…
-
geirha almost 11 yearsIf you changed PATH in
.bashrc
, that change will only be available in interactive bash sessions; it will not be visible to the process doing the keyboard shortcuts. Change the PATH in~/.profile
instead, then log out and back in. -
mariotoss almost 11 yearsI have tried to add the path where my scripts sit to the .profile, as you suggested, using either: PATH=$PATH:/home/myusername/scripts or export PATH=$PATH:/home/myusername/scripts but none of them worked (after logging in and out). However, if I add the full path of the script to the keyboard-shortcut (sh /home/username/script/nameofscript.sh) it does work. What am I doing wrong here?
-