Topic: adding terminal command to keybinding
I want to add a shortcut to do the following
$ su
$ apt-get update
$apt-get upgrade
with a shortcut (super + s)
I know the keybind, but I dont know if I need to make a script in order to dothis?
thanks!
CrunchBang Linux Forums » Help & Support (Stable) » adding terminal command to keybinding
I want to add a shortcut to do the following
$ su
$ apt-get update
$apt-get upgrade
with a shortcut (super + s)
I know the keybind, but I dont know if I need to make a script in order to dothis?
thanks!
when you separate terminal commands with a ; they will be done in order. so
sudo apt-get update; sudo apt-get upgradewhat would also work is to add in a simple check for whether the previous command executed successfully. which is better imo.
sudo apt-get update && sudo apt-get upgradeafaik this is possible in the terminal as well as in a bash script.
making a script for this isn't more difficult than this either. you just do
gedit ~/myupdatescriptadd this:
#!/bin/bash
# my update script
sudo apt-get update && sudo apt-get upgradesave that, then
chmod +x ~/myupdatescript(i might have some typos or other wrong stuff there, all this from the top of my head, never copy stuff mindlessly
)
I see what you mean, but how does the sudo actually work? won't the script stop after asking for my password?
and how do I set it up in my commands? don't I need to put the script in /usr/bin? (no, I have never been able to call my scripts from throughout the system)
thank you!!!
I see what you mean, but how does the sudo actually work? won't the script stop after asking for my password?
and how do I set it up in my commands? don't I need to put the script in /usr/bin? (no, I have never been able to call my scripts from throughout the system)
thank you!!!
No, the script won't stop after asking for your password; "sudo <dosomething>" means "temporarily give me superuser privileges and do <dosomething>, and is preferred over "su" wherever possible.
You could put the script in /usr/bin, but many of us have created a local folder for scripts; mine is ~/.scripts (read that as "/home/bsh/.scripts" where "bsh" is my username) then edit ~/.bashrc so that the PATH points to the scripts folder.
Add this to the end of ~/ .bashrc:
PATH=$PATH:~/.scripts
export PATHthis appends the ~/.scripts folder at the end of the PATH so no matter where I am the script will run.
In rhowaldt's example, he put the script in his home folder, so you'd add
PATH=$PATH:~
export PATHto .bashrc to add the home folder to the path.
Don't forget to make the scripts executable, as rhowaldt mentioned.
Last edited by 2ManyDogs (2012-01-26 01:21:35)
ok, so I have the script and it works when I call it from the terminal...
now how do I set it up to the keybind?
This is what I actually have:
<keybind key="S-u">
<action name="update">
<command>update</command>
</action>
What am I missing? do I need to call up a terminal?
Sorry, I should have been more clear about the PATH. When you add the PATH to .bashrc, it only adds your scripts folder when you run a terminal. You need to specify the full path in rc.xml. For example, I have a script that changes the wallpaper to a random image. This code calls it from rc.xml, bound to Shift-u:
<keybind key="S-u">
<action name="Execute">
<command>~/.scripts/random-wallpaper</command>
</action>
</keybind>I also think you need to use "Execute" for the action name in rc.xml (rather than "update"). And I'd personally bind it to the windows key ("W-u"), rather than shift -- I think there's less chance of typing that sequence at the wrong time.
Last edited by 2ManyDogs (2012-01-26 04:28:30)
ok, so I have the script and it works when I call it from the terminal...
now how do I set it up to the keybind?
This is what I actually have:
<keybind key="S-u">
<action name="update">
<command>update</command>
</action>What am I missing? do I need to call up a terminal?
I think you have to add a terminator command like this:
<keybind key="S-u">
<action name="Execute">
<command>terminator -e update</command>
</action>
</keybind>Already mentioned by 2ManyDogs: Don't change action name to update. It's not just a name, it's a value for openbox.
More info about openbox keybindings:
https://urukrama.wordpress.com/openbox-guide/#Key_mouse
http://openbox.org/wiki/Help:Bindings
Last edited by Tunafish (2012-01-26 10:50:40)
I think you have to add a terminator command like this:
<keybind key="S-u"> <action name="Execute"> <command>terminator -e update</command> </action> </keybind>
Thanks Tunafish.
I tried this and I still needed to specify the full path to the script.
<command>terminator -e ~/.scripts/update</command>
You don't always need to run scripts in a terminal (my random wallpaper script works fine without one, and other non-interactive tasks can be run without a terminal, using gksudo if you need su privileges). You do need a terminal for this script though, as it's nice to see what's happening and you may need to interact to answer questions from apt-get (like "do you want to continue").
Last edited by 2ManyDogs (2012-01-26 13:19:24)
I tried this and I still needed to specify the full path to the script.
Probably because ~/.scripts/ is not in your path.
^ Indeed. I usually put scripts in ~/bin (although I suppose this is improper, because they're interpreted scripts and not compiled binaries...but have a look at all the scripts in /bin.
)
^ Indeed. I usually put scripts in ~/bin
Me too.
It might still be necessary to put the whole path in the keybinding anyway.
I keep my scripts in a .scripts folder on a partition I share between a testing install and a sid install on the same machine, so I only need to maintain them in one place. I also keep them above /home because I back that up regularly and don't have to fish them all out of /bin if I need to reinstall. And when I installed a different distro on another machine it was easy to move the entire .scripts folder to that machine. I also don't like to modify anything not on /home unless absolutely necessary.
As always, there are many ways to accomplish the same end in Linux. ![]()
Allright, so now it works (after restarting openbox), but the terminal doesn't stay...
this is the action line: <command>terminator -e ./home/juan/.scripts/update</command>
Thanks!
does this work if you type it in a terminal
terminator -e ./home/juan/.scripts/updateor do you need to take out the dot
terminator -e /home/juan/.scripts/update?
does this work if you type it in a terminal
terminator -e ./home/juan/.scripts/updateor do you need to take out the dot
terminator -e /home/juan/.scripts/update?
Rhetorical that one.
jms53 says it works with the dot. So it works ![]()
Sort of solved:
Added a menu item that executes
gksudo apt-get update && gksudo apt-get upgrade.Perhaps not the most subtle way to do this, but it works, so, I'm happy. ![]()
Posts [ 17 ]
CrunchBang Linux Forums » Help & Support (Stable) » adding terminal command to keybinding
Forums powered by PunBB. Hosted by Linode.
Copyright © CrunchBang Linux.
Proudly powered by Debian GNU/Linux.
Debian is a registered trademark of Software in the Public Interest, Inc.