From ArchWiki
Revision as of 06:14, 30 August 2007 by Cheer (talk | contribs) (function getuser added)
Jump to navigation Jump to search


ACPID is a flexible and extensible daemon for delivering ACPI events. These events are triggered by certain actions, such as:

  • Pressing the Power button
  • Pressing the Sleep/Suspend button
  • Closing a notebook lid
  • (Un)Plugging an AC power adapter from a notebook

acpid can be used by itself, or combined with a more robust system such as Pm-utils and Cpufrequtils to provide a more complete power management solution.


The acpid package is available from the Current repository:

# pacman -S acpid

Edit /etc/rc.conf as root and add acpid to the DAEMONS array, for example:

DAEMONS=(syslog-ng acpid cpufreq dhcdbd networkmanager @alsa @crond ... )

Note: If you already have hal specified in your DAEMONS, there is no need to add acpid. HAL will automatically detect and load the acpid daemon.


acpid comes with a number of predefined actions for triggered events, such as what should happen when you press the Power button on your machine. By default, these actions are defined in /etc/acpi/ The following is a shortened example one such action, in this case when the Sleep Button is pressed acpid runs the command echo -n mem >/sys/power/state which should place the computer into a sleep state.

		case "$2" in
			SLPB) echo -n mem >/sys/power/state ;;
			*)    logger "ACPI action undefined: $2" ;;

Unfortunately, not every computer labels the ACPI events in the same way. For example, the Sleep button may be identified on one machine as SLPB and on another as SBTN.

To determine how your buttons or Fn shortcuts are recognized, run the following command from a terminal as root:

# tail -f /var/log/messages.log

Now press the Power button and/or Sleep button (e.g. Fn+Esc) on your machine. The result should look something this:

Aug 29 17:18:31 dublin logger: ACPI action undefined: PBTN
Aug 29 17:18:33 dublin logger: ACPI action undefined: SBTN

As you might have noticed, the Sleep button in the sample output is actually recognized as SBTN, rather than the SLPB label specified in the default /etc/acpi/ In order for Sleep function to work properly on this machine, we would need to replace SLPB) with SBTN).

Using this information as a base, you can easily customize the file to execute a variety of commands depending on which event is triggered. See the Tips & Tricks section below for more sample commands.

Tips & Tricks

Sample Events

The following are samples of events that can be dropped into the existing /etc/acpi/ script. Bolded text indicates modifications or additions to the default script. As noted above, your event labels may differ so some tweaking may be necessary.

Activate Xscreensaver upon lid closure:

       #echo "LID switched!">/dev/tty5
       /usr/bin/xscreensaver-command -lock

Execute pm-suspend (from Pm-utils) when the Sleep button is pressed:

	case "$2" in
			#echo -n mem >/sys/power/state

Extending acpid with pm-utils

Although acpid can provide basic suspend2ram out-of-the-box, a more robust system may be desired. Pm-utils provides a very flexible framework for suspend2ram (suspend) and suspend2disk (hibernate) operations, including fixes to stubborn hardware and drivers (e.g. fglrx video). pm-utils primarily consists of 2 scripts, pm-suspend and pm-hibernate, both of which can be inserted as events into acpid. For more information, check the Pm-utils wiki.

Getting user name at the current display

You can use function getuser

getuser ()
export DISPLAY=`echo $DISPLAY | cut -c -2`
user=`who | grep " $DISPLAY" | awk '{print $1}'`
export XAUTHORITY=/home/$user/.Xauthority
eval $1=$user

to achieve user at the current display. For example when you press the power button and want to shutdown KDE properly you can use this function:

               case "$2" in
                               getuser "$user"
                               echo $user > /dev/tty5
                               su $user -c "dcop ksmserver ksmserver logout 0 2 0"
                       *)    logger "ACPI action undefined $2" ;;

More Resources