You are not logged in.
I would like to make my personal handler.sh script available in aur. I think it wouldn't be such a bad idea to start packaging those scripts for people who have arch on laptops and would like to have special keys and events working without the hassle of writing their own acpid scripts. I think the main problem is that writing bash scripts for acpi events is far more complicated than editing simple and well commented configuration files. When I started with arch, I couldn't even write my own scripts which was a big showstopper for configuring acpid. I have not yet found a really good script on the net for handling major thinkpad fn keys features (perhaps, because arch is the only one, or one of few using a single acpid configuration file?).
Packaging our scripts could be a way to help beginners configure their laptops special functions easily, without the need to learn scripting first.
I personally have almost all thinpad keys working and some special stuff as well... so here is my working-state handler.sh:
#!/bin/bash
# Default acpi script that takes an entry for all actions
# NOTE: This is a 2.6-centric script. If you use 2.4.x, you'll have to
# modify it to not use /sys
# TODO: make this work with cpu governors
# TODO: make the screen switch work in console as well
# TODO: add battery reporting ability
# set various paths to ibm functions - ls /proc/acpi/ibm to add your own
bluetooth="/proc/acpi/ibm/bluetooth"
beep="/proc/acpi/ibm/beep"
light="/proc/acpi/ibm/light"
# event types
hkey="ibm/hotkey HKEY 00000080 0000"
# For acpid to interact with a running X server, we need to have permissions and additional variables
#get pid of startx
pid=$(pgrep startx)
#get pid for any other method of starting X TODO add this functionality
#get user runing the X session
user=$(ps -o user --no-headers $pid)
#get the users' home directory (red the apropriate line from passwd and cut parts not required)
userhome=$(getent passwd $user | cut -d: -f6)
#set the XAUTHORITY variable to find the magic cookie
export XAUTHORITY="$userhome/.Xauthority"
#get the DISPLAY number
for x in /tmp/.X11-unix/* ; do
number=$(echo $x | cut -c17,18)
export DISPLAY=":$number"
done
# Events are sent as command line parameters (see acpi_listen), make them a single string
event="$1"\ "$2"\ "$3"\ "$4"
########################## COMMAND HELP SECTION #################
# cpufreq-set manpage has additional info
# minspeed=$( cat /sys/devices/system/cpu/cpu0/cpufreq/cpuinfo_min_freq )
# maxspeed=$( cat /sys/devices/system/cpu/cpu0/cpufreq/cpuinfo_max_freq )
# setspeed="/sys/devices/system/cpu/cpu0/cpufreq/scaling_setspeed"
########################## END COMMAND HELP #####################
case "$event" in
# *power)
# logger "power button pressed; starting shutdown"
# ;;
# #/sbin/init 0
# #break ;; # why the hell use break
# *sleep)
# logger "sleep button pressed; initiating hibernate-ram" ;;
# #/usr/sbin/pm-suspend ;;
button/lid*)
logger "acpid: Display lid action, suspending"
/usr/sbin/pm-suspend ;;
ac*0)
logger "acpid: running on bat, activating powersave"
/usr/bin/cpufreq-set -g powersave # load the powersave governor
echo 0 > /sys/class/backlight/thinkpad_screen/brightness ;; # set brightness to the lowest level
ac*1)
logger "acpid: running on ac, activating ondemand"
/usr/bin/cpufreq-set -g ondemand # load the ondemand governor
echo 7 > /sys/class/backlight/thinkpad_screen/brightness ;; # set brighness to the highest level
# bat*0)
# logger "battery not inserted" ;;
# bat*1)
# logger "battery inserted" ;;
# BEGIN customization for ibm HOTKEYS
"$hkey"1001) # Fn+F1
logger "acpid: Fn+F1 pressed"
cpufreq-set -g ondemand ;;
"$hkey"1002) # Fn+F2
logger "acpid: Fn+F2 pressed"
cpufreq-set -g powersave ;;
"$hkey"1003) # Fn+F3
logger "acpid: blank screen (Fn+F3) pressed; switching display off"
xset dpms force off ;;
"$hkey"1004) # Fn+F4
logger "acpid: sleep button (Fn+F4) pressed; initiating hibernate-ram"
/usr/sbin/pm-suspend ;;
"$hkey"1005) # Fn+F5; toggle bluetooth
logger "acpid: bluetooth button (Fn+F5) pressed; toggling bluetooth"
case $( grep status $bluetooth ) in
*disabled) echo enable > $bluetooth ;;
*enabled) echo disable > $bluetooth ;;
esac ;;
"$hkey"1006) # Fn+F6; toggle wireless on/off
logger "acpid: Fn+F6 pressed"
if ifconfig | grep -q ath0 ; then
ifconfig ath0 down
else
ifconfig ath0 up
fi ;;
"$hkey"1007) # Fn+F7
############what action should be taken????
#Using Xrandr
#
#To use the TVout on Radeon 7500 type following:
#$ xrandr --output S-video --set load_detection 1
#$ xrandr --addmode S-video 800x600
#$ xrandr --output S-video --mode 800x600
#
#And set mode PAL or NTSC with:
#$ xrandr --output S-video --set tv_standard ntsc
#
#If you want to use XVideo overlay on TV, try following command:
#$ xvattr -a XV_CRTC -v 1
#
#
logger "acpid: Fn+F7 pressed, toggling screen"
# if -n $DISPLAY ; then
# printenv > /home/jarda-wien/variables_x
# else
# printenv > /home/jarda-wien/variables_no_x
# fi
case "$(/usr/bin/xrandr -q | grep VGA-0)" in # TODO xrandr is relevant only in a X session, make this work in console too
*1280x1024*) # external monitor is in use, switch off
/usr/bin/xrandr --output VGA-0 --off ;;
"VGA-0 connected"*) # external monitor is connected but case 1 didn't apply, switch on
/usr/bin/xrandr --output VGA-0 --mode 1280x1024 --right-of LVDS ;;
*) # any other case
logger "acpid: external screen not found" ;;
esac ;;
"$hkey"1008) # Fn+F8
logger "acpid: Fn+F8 pressed"
echo 3 > $beep ;;
"$hkey"1009) # Fn+F9; use ath_pci driver
logger "acpid: Fn+F9 pressed; switching to ath_pci"
/home/jarda-wien/bin/toggleWIFI.sh ath_pci ;;
"$hkey"100a) # Fn+F10; use ath5k driver
logger "acpid: Fn+F10 pressed; switching to ath5k"
/home/jarda-wien/bin/toggleWIFI.sh ath5k ;;
"$hkey"100b) # Fn+F11; use ndiswrapper driver
logger "acpid: Fn+F11 pressed; switching to ndiswrapper"
/home/jarda-wien/bin/toggleWIFI.sh ndiswrapper ;;
"$hkey"100c) # Fn+F12
logger "acpid: hibernate button (Fn+F12) pressed; initiating hibernate"
/usr/sbin/pm-hibernate ;;
"$hkey"100d) # Fn+Backspace
logger "acpid: Fn+Backspace pressed"
echo 3 > $beep ;;
"$hkey"100e) # Fn+Insert
logger "acpid: Fn+Insert pressed"
echo 3 > $beep ;;
"$hkey"100f) # Fn+Delete
logger "acpid: Fn+Delete pressed"
echo 3 > $beep ;;
"$hkey"1013) # Fn+PgDn
logger "acpid: Fn+PgDn pressed"
echo 3 > $beep ;;
"$hkey"5001) ;; # This is the lid CLOSE event, it is already handled above
"$hkey"5002) ;; # This is the lid OPEN event, it is already handled above
"$hkey"1014) # Fn+Space
logger "acpid: zoom button (Fn+Space) pressed"
case $( grep status $light ) in
*on) echo off > $light ;;
*off) echo on > $light ;;
esac ;;
"$hkey"1018) # Access IBM
logger "acpid: Access IBM button pressed"
ksysguard ;;
# BEGIN customization for ibm DOCK
# "$dock"1)
# logger "dock eject request" ;;
# "$dock"2)
# logger "laptop was undocked" ;;
# "$dock"3)
# logger "laptop was docked" ;;
# BEGIN customization for ibm BAY
# "$bay"3*)
# logger "ultrabay eject request" ;;
# "$bay"1*)
# logger "ultrabay eject lever inserted" ;;
*) # Everything else
logger "acpid: $event is not defined" ;;
esac
I realise it needs a lot of cleaning and perhaps rewriting too, but still, there is some good functionality in it...
So what do you think about the idea?
Offline
The best thing (and simplest) Arch can do, is to use Debian acpi-support package, which has all those scripts already written.
I use it on my laptop, and I was surprised that it isn't even in community repository. IMHO it's so essential that it should be in extra repo
Last edited by AdeBe (2009-03-02 18:42:32)
Offline
cool didn't know about that! it actually is not in community, only in aur.... but then again, the debian scripts lack the siplicity of one handler script:|
Offline
What is a handler script?
Offline
What is a handler script?
I meant the /etc/acpi/handler.sh script
Offline
I knew what you meant, I just didn't know what it was and what it is doing, but I did a little googling and read about it. Im running Arch on a laptop and ACPI already works, so I dont really se why it is needed?
When I close the lid, or even when I remove the power cable it goes to standbymode
It is a bit annoying that it happenns when I remove the power cable though.
I was going to try the script to see if it fixed my power cable problem but I cannot contact any of the ftp servers so I can't get the acpid package, I guess its something with my Internet, cause all ftp servers cannot be down at the same time? The wierd thing is that I can browse trough them, but when I choose to download a file it refuses to begin downloading
Offline
well that is what acpid is here for... you can configure exacly what happens when.
if you are able to browse ftp servers, it is probably a problem with your pacman mirrorlist. please, make a new post for that in the apropriate section of the forum for that.:cool:
Offline
It was just a syntax error in pacman.conf
Now I'am going to try out acpid, thanks anyway ;-)
Offline
The best thing (and simplest) Arch can do, is to use Debian acpi-support package, which has all those scripts already written.
I use it on my laptop, and I was surprised that it isn't even in community repository. IMHO it's so essential that it should be in extra repo
thats a quite fat package
i think there could be a simpler solution
☃ Snowman ☃
Offline
thats a quite fat package
i think there could be a simpler solution
that is exacly what I think. What I am suggesting is to have laptop-brand (perhaps special models) specific acpid config packages instead of the acpi-support package "try to fit all" approach
edit: typos
Last edited by jarda-wien (2009-03-03 13:49:26)
Offline
i wrote a small python/bash script to configure acpi buttons
for now it works like the following:
1. script waits for event
2. script asks you to specify command
3. script asks you to specify a description
this could be modified to manually map acpid events to predefined scripts, if anyone's interested
url:
see 2 posts below
Last edited by robmaloy (2009-03-05 07:07:44)
☃ Snowman ☃
Offline
i wrote a small python/bash script to configure acpi buttons
for now it works like the following:
1. script waits for event
2. script asks you to specify command
3. script asks you to specify a descriptionthis could be modified to manually map acpid events to predefined scripts, if anyone's interested
I am sorry robmaloy, but the file seems to be not accessible.
btw do I understand this right that it could be configured as an acpid replacement?
Last edited by jarda-wien (2009-03-04 18:29:11)
Offline
its not a replacement, its just 'handler.sh' with a simple configuration script
sorry for the broken link,
working link:
http://rob.kingofnerds.net/arch/acpy-03-04-2009.tar
☃ Snowman ☃
Offline
I am sorry I don't have much time this week, but I will try it and post back.:cool:
Offline
Hi jarda-wien, I was just beginning to write such a script to have a full use of my thinkpad's Fn buttons.
On my R60 I have the thinkpad_acpi module loaded and the stock acpid config and 2 keys work nativeley: Fn + PAGEUP (light) and Fn + INS / END (brightness). The strange think is that not only they work natively but they don't seem to generate events recognized by acpid.
Anyway thanks for sharing yours, especially the part dealing with the X server communication hehe.
I don't know python but if I find improvements to make on the bash side I'll make you know
Offline
The strange think is that not only they work natively but they don't seem to generate events recognized by acpid.
You'll probably find that this is being handled by the bios. The same goes for the volume buttons as well.
Offline
well those keys really are handled by bios. you can check what event types are sent through acpid by running acpi_listen and pressing the hotkeys. the thinklight and volume keys (possibly others as well...) do not send events on my T41
as I wrote about not having time this week long time ago, I have to justify the long delay by saying that I have been learning touch typing + python
in the end I think I will put the script, once cleaned up a little to aur and see what will happen
Offline
FWIW, I can't get this thing to work no matter what I do.
I didn't have a handler.sh script at all when I looked for it, instead there were two folders called "actions" and "events". I just want it to scale my CPU and turn off/on laptop mode when I take it on and off battery power and suspend on shutting the lid. So I put this in there:
#!/bin/bash
# Default acpi script that takes an entry for all actions
# NOTE: This is a 2.6-centric script. If you use 2.4.x, you'll have to
# modify it to not use /sys
# TODO: make this work with cpu governors
# TODO: make the screen switch work in console as well
# TODO: add battery reporting ability
case "$event" in
# *power)
# logger "power button pressed; starting shutdown"
# ;;
# #/sbin/init 0
# #break ;; # why the hell use break
# *sleep)
# logger "sleep button pressed; initiating hibernate-ram" ;;
# #/usr/sbin/pm-suspend ;;
button/lid*)
logger "acpid: Display lid action, suspending"
/usr/sbin/pm-suspend ;;
ac*0)
logger "acpid: running on bat, activating powersave"
/usr/bin/cpufreq-set -g powersave # load the powersave governor
echo 0 > /sys/class/backlight/thinkpad_screen/brightness ;; # set brightness to the lowest level
/etc/laptop-mode/laptop-mode start
ac*1)
logger "acpid: running on ac, activating ondemand"
/usr/bin/cpufreq-set -g ondemand # load the ondemand governor
echo 7 > /sys/class/backlight/thinkpad_screen/brightness ;; # set brighness to the highest level
/etc/laptop-mode/laptop-mode stop
esac
Rebooted, on battery power, it's using "performance" and shutting the lid doesn't suspend.
Like I said, I had NO handler.sh prior to this. Despite the wiki saying "If you have properly followed the steps above, the file should already exist and be executable" it didn't even though I followed the steps exactly. I'm getting monumentally annoyed with things, any nudge would be great.
And in the midst of such perfection,
I can't help but feel diseased.
Offline
Like I said, I had NO handler.sh prior to this. Despite the wiki saying "If you have properly followed the steps above, the file should already exist and be executable" it didn't even though I followed the steps exactly. I'm getting monumentally annoyed with things, any nudge would be great.
you could try adding
logger "received ACPI event:" $event
before the "case" statement in your handler.sh
then check /var/log/messages.log
if / why they don't match
Last edited by robmaloy (2009-04-27 14:04:18)
☃ Snowman ☃
Offline
Addendum. I installed the acpi-support package from the AUR. That gave me a whole massive new setup. Added the code for logging. Messages.log has nothing. Literally no anything when I unplug, when I shut the lid, anything of that sort.
And in the midst of such perfection,
I can't help but feel diseased.
Offline
Added the code for logging. Messages.log has nothing
chmod +x /etc/acpi/handler.sh ?
acpid running?
run acpi_listen and push the lid/power/sleep button.
Last edited by robmaloy (2009-04-28 11:23:41)
☃ Snowman ☃
Offline
button/lid LID 00000080 00000005
button/lid LID 00000080 00000006
battery BAT0 00000080 00000001
battery BAT0 00000081 00000001
ac_adapter ACAD 00000080 00000001
battery BAT0 00000080 00000001
battery BAT0 00000080 00000001
First two are closing and opening the lid.
Third is removing the plug.
The remaining four(?) are what happens when I replace the plug.
Any ideas what I should do with them now?
And in the midst of such perfection,
I can't help but feel diseased.
Offline
Anything? Here's my handler.sh, how do I combine the information from the above into this?
#!/bin/sh
# Default acpi script that takes an entry for all actions
# NOTE: This is a 2.6-centric script. If you use 2.4.x, you'll have to
# modify it to not use /sys
minspeed=`cat /sys/devices/system/cpu/cpu0/cpufreq/cpuinfo_min_freq`
maxspeed=`cat /sys/devices/system/cpu/cpu0/cpufreq/cpuinfo_max_freq`
setspeed="/sys/devices/system/cpu/cpu0/cpufreq/scaling_setspeed"
set $*
case "$1" in
button/power)
#echo "PowerButton pressed!">/dev/tty5
case "$2" in
PWRF) logger "PowerButton pressed: $2" ;;
*) logger "ACPI action undefined: $2" ;;
esac
;;
button/sleep)
case "$2" in
SLPB) echo -n mem >/sys/power/state ;;
*) logger "ACPI action undefined: $2" ;;
esac
;;
ac_adapter)
case "$2" in
AC)
case "$4" in
00000000)
echo -n $minspeed >$setspeed
#/etc/laptop-mode/laptop-mode start
;;
00000001)
echo -n $maxspeed >$setspeed
#/etc/laptop-mode/laptop-mode stop
;;
esac
;;
*) logger "ACPI action undefined: $2" ;;
esac
;;
battery)
case "$2" in
BAT0)
case "$4" in
00000000) #echo "offline" >/dev/tty5
;;
00000001) #echo "online" >/dev/tty5
;;
esac
;;
CPU0)
;;
*) logger "ACPI action undefined: $2" ;;
esac
;;
button/lid)
#echo "LID switched!">/dev/tty5
;;
*)
logger "ACPI group/action undefined: $1 / $2"
;;
esac
This is getting bothersome.
EDIT: I've gotten the lid to activate suspend, but I'd really like it if the rest would work because that's a boatload of commands I'd be saving myself from having to execute.
Last edited by SomeGuyDude (2009-04-29 12:17:42)
And in the midst of such perfection,
I can't help but feel diseased.
Offline
you could also try this:
http://rob.kingofnerds.net/arch/acpy-03-04-2009.tar
(run as root, use at your own risk!)
☃ Snowman ☃
Offline
Yeah I'm a little wary of that. I'd really prefer to stick with the simple stuff.
And in the midst of such perfection,
I can't help but feel diseased.
Offline