0

For a while now I have been assigning some of my personal shell scripts to keyboard shortcuts in Ubuntu (by going through Settings > Keyboard > Shortcuts and assigning them under Custom).

After upgrading to 15.10 however, I can no longer run shell scripts from keybaord shortcuts this way. Has the syntax changed, or are there new requirements? Previously, it had been enough for me to set the command as ~/myscript.sh, but this no longer works.

My script has executable permissions, and running it from the command line is no problem. I have tried:

./myscript.sh
/home/me/myscript.sh
bash /home/me/myscript.sh
sh /home/me/myscript.sh

Among many other combinations of paths and commands. None of these have any response, and all of them work fine when pasted directly into the terminal. I have also tried assigning the script to other key combinations, but none of them have any response (though the key combinations themselves work fine if I assign another command that is not a shell script).

Running scripts this has been a crucial part of my daily workflow, so any suggestions would be appreciated. Thank you!

5
  • 1
    You could try adding it directly to the configuration file. In Xfce it is /home/USER/.config/xfce4/xfconf/xfce-perchannel-xml/xfce4-keyboard-shortcuts.xml Even though you have tried different key combinations, you could still have a conflict with it already having been assigned elsewhere. Therefore you may want to check the configuration file to make sure the keyboard combination is not duplicated. Be sure to log out and in again before trying.
    – jbrock
    Nov 2, 2015 at 20:30
  • Thank you @jbrock, but I don't think this will work because for example, if I bind to Alt+backslash it will not work to run my script, but if I change it so the same key combination runs a different command that is not a shell script (e.g., terminator to launch the terminator app) it works for this command. However, I am at my work machine which is running on 15.04 still, and has the script bound to Alt+backslash and working, and I realized that I have the keys bound to ./myscript.sh, which is the one combination I didn't try at home. Not sure why this would work, but will try tonight
    – elethan
    Nov 2, 2015 at 20:42
  • Unfortunately, ./myscript.sh doesn't work either...
    – elethan
    Nov 3, 2015 at 2:22
  • 1
    If other commands work for your shortcut and the script runs, if you start direct in a terminal, perhaps there is a problem in the script in interaction with the shortcut. Try another simple script or add your script to your question.
    – A.B.
    Nov 3, 2015 at 6:13
  • Try starting gnome-settings-daemon or unity-settings-daemon form command line and then test the shortcuts, starting with bash -c /path/to/script.sh Nov 3, 2015 at 22:48

1 Answer 1

0

After loads of experimentation with steps suggested in the comments, among other things, I figured out that I can run shell scripts fine, and I can even run the desired script fine, it is just one particular line of the script that was failing.

The most important part of my shell script is actually the invocation of a python script. The python script needs access to modules outside of my normal PATH. For this reason, in my .bashrc I add the appropriate paths to my PYTHONPATH. However, it seems like commands that are run from keyboard shortcuts in this way ignore the contents of my .bashrc. I am curious where/how these commands are executed under the hood, but I will post another question for this.

The solution was to add necessary paths to my PYTHONPATH in the shell script itself with the following line, so they are accessible to the python script:

 export PYTHONPATH="/path/to/crucial/python/library"
1
  • 1
    From within the script, you can add a path by: import sys and (next line) sys.path.insert(0, "/path/to/your/package_or_module"). Nov 4, 2015 at 7:00

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.