Run custom script/program on linux hibernate/suspend/thaw/resume/lid-close/lid-open

For hibernate/suspend/resume:

Any executable file under /etc/pm/sleep.d will be executed one any of the above actions with a string inside the second parameter(which is args[1] in C or $1 in shell). This parameter may reads hibernate, thaw, suspend or resume depending on the operation the system is doing.

Just write a script or a program that does a certain operation according to the parameter recieved and throw it into the dictionary, mark it as executable(chmod) and it should do the job.

For lid close/lid open:
Solutions from here:
http://forums.fedoraforum.org/showthread.php?t=291877
and here:
https://wiki.archlinux.org/index.php/Acpid
looks pretty relevant. However, None of them works.

Still finding solutions.

2017/4/18 19:48