+-------------------------------------------------------------------+ | | | WIKI - [acpid] Handle all events in a single script | | | +-------------------------------------------------------------------+ PREREQUISITES * Make sure that all ACPI-related kernel options are enabled. More info: https://wiki.gentoo.org/wiki/ACPI#Kernel IDENTIFYING ACPI EVENTS * Enable acpid. $ ln -s /etc/sv/acpid/ /var/service/ * Run acpi_listen. This waits for ACPI events and outputs them. # For this example, pressing the volume mute button will print something like: $ button/mute MUTE 00000080 00000000 K NOTE: Some 'Fn + *' keys might not appear as they are hardware-bound (e.g. WLAN toggle). Just test them all and see what works. For most laptops, this will also detect lid events (e.g. opening or closing). READ ALL EVENTS * Create a file under /etc/acpi/events/ (just create these directories if they are missing) containing the following: # /etc/acpi/events/anything event=.* action=/etc/acpi/handler.sh %e * This will match any detected event and run the action file (see below). THE HANDLER SCRIPT * During an event, acpid will run a corresponding action which can now be handled by a single script. This is possible as the events are passed literally as multiple parameters into the script. As for our example: button/mute MUTE 00000080 00000000 K $1=button/mute $2=MUTE $3=00000080 $4=00000000 $5=K * Here's a very simple script: # /etc/acpi/handler.sh #!/bin/sh case $1 in button/mute) amixer sset Master toggle ;; esac # Don't forget to make this file executable $ chmod +x /etc/acpi/handler.sh * Restart `acpid`. $ sv restart acpid