Next: , Previous: Events, Up: Top

11 Mapping Scripts to Events

All scripts must use powersaved_script_return to tell powersaved when the event is finished. Otherwise no other event will be started until the previous event times out (after 120 seconds).

The syntax is:
powersaved_script_return $EVENT_ID $RET "$MESSAGE"

$EVENT_ID is the number given to the script as positional parameter $4.
$MESSAGE is just informal, except for return codes 2 and 4.
Possible return codes $RET are:
0 - execution of the event finished successfully
1 - execution of the event finished, but failed
2 - request a popup by the client, event not finished
3 - request a screenlock by the client, event not finished
4 - request a progress bar popup by the client, event not finished
There may be additional codes added in the future.

This is example code to use in your own scripts:
# example script for events in powersaved
# parameters:
# - $1 event type
# - $2 current scheme
# - $3 ACPI event line
# - $4 Event-ID. Needed for $SCRIPT_RETURN
# # source helper_functions to get $PATH, $SCRIPT_RETURN, EV_ID (among others)
. /usr/lib/powersave/scripts/helper_functions
# Note: this sets a trap on "EXIT", so you must exit the script via the
# (also provided) EXIT function after calling $SCRIPT_RETURN
# If you don't call EXIT, the trap will call $SCRIPT_RETURN with return code 1
# this is stupid, you'd like to do something useful here :-)
case $3 in
logger "button-event"
*) logger "non-button-event"
$SCRIPT_RETURN $EV_ID 1 example script failed"
# always call $SCRIPT_RETURN before exiting:
$SCRIPT_RETURN $EV_ID 0 "example script succeeded"

There are various scripts in the contrib directory (the "example_event_script" has comments on what is provided by helper_functions) or have a look at the simple "debug_events" script in the scripts directory for other examples.