Search Members Help

» Welcome Guest
[ Log In :: Register ]

Mini-ITX Boards Sale, Fanless BareBones Mini-ITX, Bootable 1G DSL USBs, 533MHz Fanless PC <-- SALE $200 each!
Get The Official Damn Small Linux Book. DSL Market , Great VPS hosting provided by Tektonic
Pages: (2) </ [1] 2 >/

[ Track this topic :: Email this topic :: Print this topic ]

reply to topic new topic new poll
Topic: Laptop lid script< Next Oldest | Next Newest >
Zucca Offline





Group: Members
Posts: 524
Joined: Feb. 2006
Posted: April 11 2007,20:59 QUOTE

You need to replace /proc/acpi/button/lid/C162/state to fit your own laptop. But it's somewhere in the /proc/acpi directory.

Code Sample
#!/bin/bash

LIDSTATE="open"

while true
do
 sleep 1s
 if grep open /proc/acpi/button/lid/C162/state >> /dev/null && [ "$LIDSTATE" == "closed" ]; then
   LIDSTATE="open"
   # Run commands to set you as 'Online'.
 elif grep closed /proc/acpi/button/lid/C162/state >> /dev/null; then
   LIDSTATE="closed"
   # Run commands to set you as 'away'.
  fi
done


You may get the point...
This is really nice script to command your IRC client to set you as away when you close the lid. Also for ICQ and M$N.
But personally I'd put a hd spindown command there (as last command when closing lid). ;) With few secs of delay...

Basically it checks every second if the state of your lid has changed and if it has then it performs commands you have entered.

Maybe 'source /etc/online.run' and '/etc/source away.run' or something like that would be nicer. Then you wouldn't need to edit script itself anymore...


--------------
Do you have it? - http://dy.fi/mak
Back to top
Profile PM WEB ICQ MSN 
Juanito Offline





Group: Members
Posts: 1601
Joined: Sep. 2005
Posted: April 12 2007,03:26 QUOTE

Alternatively, you could load acpid to detect the lid state for your machine automatically and run the script of your choice
Back to top
Profile PM 
mikshaw Offline





Group: Members
Posts: 4856
Joined: July 2004
Posted: April 12 2007,13:45 QUOTE

As usual, I can't help but pick at little optimization opportunities.
Is it necessary to check the "state" file _AND_ set a state variable explicitly?
To reduce redundancy and filesize, you can check the state file once and determine your action from that.
If you have only two possible options, "elif" is unnecessary

This is untested, since i don't have/use acpid or a laptop =o)
The LIDSTATE especially may not work, since i have no idea what the state file looks like.
Code Sample
#!/bin/bash

while true
do
sleep 1s
LIDSTATE=`cat /proc/acpi/button/lid/C162/state`
if  [ "$LIDSTATE" == "closed" ]; then
  # Run commands to set you as 'away'.
else
  # Run commands to set you as 'Online'.
 fi
done

Also seems to me that one second is a pretty high frequency. Raising that number would be easier on your processor. It's just an opinion, though.


--------------
http://www.tldp.org/LDP/intro-linux/html/index.html
Back to top
Profile PM WEB 
Zucca Offline





Group: Members
Posts: 524
Joined: Feb. 2006
Posted: April 12 2007,20:41 QUOTE

This is why:
Code Sample
$ cat /proc/acpi/button/lid/C162/state
state:      open


And I need to set the variable because that script would then perform commands each second when lid is closed/open. I need to set that variable to tell script that it has already performed those tasks on open/close and won't "reperform" those commands anymore until state has changed.

Every second... Hm. It could be like every 10 seconds. That's true.


--------------
Do you have it? - http://dy.fi/mak
Back to top
Profile PM WEB ICQ MSN 
mikshaw Offline





Group: Members
Posts: 4856
Joined: July 2004
Posted: April 12 2007,21:01 QUOTE

I see...hadn't thought about rerunning the same commands for no reason (this thread was the first thinking I did today =o))...good point.

It still seems to me that grepping the state file more than once in a loop may be unnecessary, but it's a lot better compared to what I was thinking this morning.


--------------
http://www.tldp.org/LDP/intro-linux/html/index.html
Back to top
Profile PM WEB 
6 replies since April 11 2007,20:59 < Next Oldest | Next Newest >

[ Track this topic :: Email this topic :: Print this topic ]

Pages: (2) </ [1] 2 >/
reply to topic new topic new poll
Quick Reply: Laptop lid script

Do you wish to enable your signature for this post?
Do you wish to enable emoticons for this post?
Track this topic
View All Emoticons
View iB Code