But, if you (like me) don't have keyboards with fancy shortcut buttons, why not use that same power button for some shortcut. Or, you can make fun of your Windows friends just by showing what power and mind-boggling functionality Linux have and just waits for yours ideas to unleash it. I think this is great example of that.
I will use Ubuntu to set it up, but, with minor (or even none) modification, this should work on any distro. First you will need, is to remove annoying gnome log-off screen that shows up when you press power button. For this, we will need to change two keys in gconf. Start gconf-editor and change those two keys:
- /apps/gnome-power-manager/action_button_power
- /apps/gnome-power-manager/buttons/power
Enable/disable internet (forwarding)
I already had two little script to enable or disable internet to some users I am routing internet to. These are some iptables stuff (something like `iptables -I FORWARD -p ALL -s 192.168.0.122 -j DROP`) and I had to open console, execute it and later enable it. This can be done with this in /etc/acpi/powerbtn.sh:
#! /bin/shThis is stupid script. It checks for existence of file /var/tmp/internet_off that signalizes if forwarding is on. It then executes appropriate scripts. If you have someone dumb enough, you can tell them that they have no internet because your computer is turned off, and what they see on monitor is just a picture, or drop them a story about virtual (wau!) machine that run even when computer is off (everyone heard of vmware) - something like that:) You can even confirm this by pressing button in front of them to enable or disable their internet access.
if [ -f /var/tmp/internet_off ]; then
/etc/rc.start_internet
rm /var/tmp/internet_off
else
/etc/rc.stop_internet
touch /var/tmp/internet_off
fi
Starting firefox
I use firefox all day. If I ever want to dedicate any button to any program, that is certainly firefox. But to start GUI program in shell script that is run as root, we need some workarounds. For example, you need to set DISPLAY and XAUTHORITY environment variable.
#! /bin/shBut, this script have few defects. If firefox is running, it will launch another windows, and we see 'yourusername' is all around. This is improved version:
export DISPLAY=:0
export XAUTHORITY=/home/yourusername/.Xauthority
sudo -u yourusername firefox
#! /bin/shIf firefox is running, it will just open new empty tab, otherwise it will launch it normally. Also, your username is pulled up as variable, so you just need to change second line to your username and this script will work. Have fun!
USERNAME=yourusername
export DISPLAY=:0
export XAUTHORITY=/home/$USERNAME/.Xauthority
if ps -U $USERNAME -u $USERNAME|grep firefox; then
sudo -u $USERNAME firefox -new-tab about:blank
else
sudo -u $USERNAME firefox
fi
Further ideas
Only one function for button is nothing. Maybe we can split two different functionality by defining click and double-click on power button. Simple creating file on first click, and checking if file was created 2 seconds before current time (I will not go into details here). Also, you could use that button to open CD tray, why not:) Like anything in Linux, your creativity is your only limit. Do you have any ideas what to do else with this button? What would you put in /etc/acpi/powerbtn.sh?
No comments:
Post a Comment