Take the 2-minute tour ×
Ask Ubuntu is a question and answer site for Ubuntu users and developers. It's 100% free, no registration required.

Just wondering; how do I bind .sh files to run when I press a particular key combination? (like Alt+S)

Thanks,

Dante

share|improve this question
add comment

4 Answers 4

up vote 2 down vote accepted

You can use the keyboard shortcuts interface to do this. Remember to add the full path. alt text

share|improve this answer
3  
To clarify, tildes are not expanded. –  Jamie Schembri Nov 26 '10 at 21:55
    
exactly that's what I meant :) thanks ^^ –  RolandiXor Nov 26 '10 at 22:51
add comment

Goto System>>Preferences>>Keyboard Shortcuts

It will open a window click add alt text

After clicking add it will show you a window with Name and Command.You can write any name there and in command you should give the full path of the file with bash in-front bash /path/to/the/file.sh

alt text

After adding the Name & Command.You can assign the shortcut key.

share|improve this answer
    
how to run the script which needs sudo permission inside ? –  silentbang Jul 7 '11 at 12:26
add comment

xbindkeys allows you to saves multiple configurations (if you want that flexibility).

Also xbindkeys gives you many more key-combinations, because it (optionally) allows you to make Numlock, ScrollLock, and CapsLock states significant...

Another feature which is not found in Keboard Shortcuts is that you can use ~/ and $HOME/ for your home directory, instead of having to hard-code it.

To install xbindkeys, and xbindkeys-config (the GUI for xbindkeys)

sudo apt-get install xbindkeys xbindkeys-config  

To create the default config file for xbindkeys

xbindkeys --defaults > $HOME/.xbindkeysrc  

Then run:

xbindkeys
xbindkeys-config

And for your first keybinding, you may find it useful to assign Ctrl+Shift+Alt+X, or whatever you prefer, to xbindkeys-config

To keep the xbindkeys hotkeys active ever time you start the computer...

Main Menu
  System  
    Preferences  
      Startup Applications  
        [ Add ]  
          Name:     xbindkeys  
          Command:  xbindkeys  
          Comment:  xbindkeys  
share|improve this answer
add comment

Just for completeness: If you are using Compiz you can set custom keyboard and mouse shortcuts using CCSM (Compiz Config Settings Manager) and the Commands plugin.

Just put in the name of your sh-script (for example "CustomScript" in the attached screenshot) and give it a custom key binding in the Key Bindings tab. Your script needs to be placed in a directory that is monitored by Ubuntu for this to work. I do place all of my scripts in the /usr/local/bin directory.

Make sure that your script is executable by applying chmod +x CustomScript in a terminal and note that all words are case sensitive.

Compiz allows to export all settings including shortcuts which is very useful for settings up similar machines.

(see screenshot)

share|improve this answer
add comment

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

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