You are not logged in.
Here's my lidbtn.sh. I hope some finds it useful. Any comments, suggestions or criticism are welcome.
This is what it does:
If I'm running on batteries, it shuts down.
If I'm plugged in, but with no external monitor, it suspends.
If I'm plugged in with an external monitor, it switches off the internal screen, and up the resolution on the external monitor.
If I open the lid and I'm using the external monitor it switched on the internal monitor, and lowers the resolution of the external monitor to match the internal.
#!/bin/sh
LID_STATE=`cat /proc/acpi/button/lid/LID/state | awk '{print $2 }'`
AC0_STATE=`cat /proc/acpi/ac_adapter/AC0/state | awk '{print $2 }'`
VGA_STATE=`xrandr --prop -display :0.0 | grep "VGA connected [0-9]" | wc -l`
LVDS_STATE=`xrandr --prop -display :0.0 | grep "LVDS connected [0-9]" | wc -l`
if [ $LID_STATE = "closed" ]; then
if [ $AC0_STATE = "on-line" ]; then
if [ $VGA_STATE = "1" ]; then
if [ $LVDS_STATE = "1" ]; then
xrandr -display :0.0 --output LVDS --off
xrandr -display :0.0 --output VGA --mode 1024x768
fi
else
/etc/acpi/suspend2ram.sh
fi
else
/sbin/fastshutdown.sh
fi
else
if [ $VGA_STATE = "1" ]; then
xrandr -display :0.0 --output LVDS --mode 1024x600
xrandr -display :0.0 --output VGA --mode 1024x600
fi
fi
exit 0Last edited by Mue (2008-08-02 5:02:49 pm)
Offline
Good work!
I am looking for a way to Shut down on lid close normally, but while I am listening to music with my eeepc, I would like it to Do Nothing On Closing The Lid, just Shutting off screen. Any idea how this can be done?
Offline
Evening Albkwan,
The first step is detecting if your music playing app is running.
You can use ps to list all the running processes:
ps -A
You can then use grep to search the output from this to see if you music app is listed. If you are using amarok (the default music manager thingy) you can use:
ps -A | grep amarokapp
If amarokapp is running you'll get a line of text back telling you the process id and name.
Then to make this more accessible inside the script, I would pipe it to wc the word counter and ask it to count the number of lines.
ps -A | grep amarokapp | wc -l
Typing this into a terminal window should display the number of copies of amarokapp processes that are running.
So far so good, now to use this inside the lidbtn.sh script. Adding a line near the beginning of the script to execute the above command and store the output in a variable. Something like:
MUSIC_APP_STATE=`ps -A | grep amarokapp | wc -l`
Make sure you use back ticks ` instead of apostrophes '
Then further down in the lidbtn.sh, before shutting down, check that the music player is NOT running with something like:
if [ $MUSIC_APP_STATE == "0" ]; then
I hope that gets you some if not all of the way there. The main problem with this approach is it only checks if amarok is running, not if it is actually playing music. When you close the amarok window, it doesn't quit, it just minimizes to the task bar, so you'll have to quit it before closing the lid will shutdown you eee.
Mue.
Last edited by Mue (2008-08-04 3:32:03 pm)
Offline
Hi, Mue,
Thanks for the advice. I have run some test and this is what I have worked out:
#!/bin/sh
LID_STATE=`cat /proc/acpi/button/lid/LID/state | awk '{print $2 }'`
#AC0_STATE=`cat /proc/acpi/ac_adapter/AC0/state | awk '{print $2 }'`
VGA_STATE=`xrandr --prop -display :0.0 | grep "VGA connected [0-9]" | wc -l`
#LVDS_STATE=`xrandr --prop -display :0.0 | grep "LVDS connected [0-9]" | wc -l`
MUSIC_APP_STATE=`ps -A | grep amarokapp | wc -l`
if [ $LID_STATE = "closed" ] ; then
# /etc/acpi/suspend2ram.sh
if [ $VGA_STATE = "1" ]; then
xrandr -display :0.0 --output LVDS --off
else
if [ $MUSIC_APP_STATE == "1" ]; then
if [ $LID_STATE = "closed" ] ; then
su user -c "DISPLAY=:0 xset dpms force suspend"
elif [ $LID_STATE = "open" ] ; then
su user -c "DISPLAY=:0 xset dpms force on"
fi
else
/sbin/fastshutdown.sh
fi
fi
fi
exit 0Now my eeepc will normally shut down on lid close. But when the display is set to external monitor, it will just switch off the LCD. And when I am playing music from Amarok, it will just blank screen (any mouse movement will resume).
Thanks again
albkwan
Offline
Fantastic work - very useful - thanks! I had no idea this was possible...
Offline
A little enhancement: This time, the script will detect any of the following music players running, and will do the same trick: amarok, audacious, vlc, smplayer, mpg321, xmms
#!/bin/sh
LID_STATE=`cat /proc/acpi/button/lid/LID/state | awk '{print $2 }'`
#AC0_STATE=`cat /proc/acpi/ac_adapter/AC0/state | awk '{print $2 }'`
VGA_STATE=`xrandr --prop -display :0.0 | grep "VGA connected [0-9]" | wc -l`
#LVDS_STATE=`xrandr --prop -display :0.0 | grep "LVDS connected [0-9]" | wc -l`
MUSIC_APP_STATE_1=`ps -A | grep amarokapp | wc -l`
MUSIC_APP_STATE_2=`ps -A | grep audacious | wc -l`
MUSIC_APP_STATE_3=`ps -A | grep wxvlc | wc -l`
MUSIC_APP_STATE_4=`ps -A | grep mplayer | wc -l`
MUSIC_APP_STATE_5=`ps -A | grep mpg321 | wc -l`
MUSIC_APP_STATE_6=`ps -A | grep xmms | wc -l`
MUSIC_APP_STATE=${MUSIC_APP_STATE_1}${MUSIC_APP_STATE_2}${MUSIC_APP_STATE_3}${MUSIC_APP_STATE_4}${MUSIC_APP_STATE_5}${MUSIC_APP_STATE_6}
if [ $LID_STATE = "closed" ] ; then
# /etc/acpi/suspend2ram.sh
if [ $VGA_STATE = "1" ]; then
xrandr -display :0.0 --output LVDS --off
else
if [ $MUSIC_APP_STATE != "000000" ]; then
if [ $LID_STATE = "closed" ] ; then
su user -c "DISPLAY=:0 xset dpms force suspend"
elif [ $LID_STATE = "open" ] ; then
su user -c "DISPLAY=:0 xset dpms force on"
fi
else
/sbin/fastshutdown.sh
fi
fi
fi
exit 0Offline
Awesome script. It does sensible things depending on what's plugged in.
The only thing I'd worry about is running with the lid closed. A fair amount of heat bleeds out the keyboard, and that heat would now be fatiguing the LCD (even though it's off).
But if you've been doing it and it's been fine, it's worth trying out!
*EDIT* it would NOW be fatiguing the LCD, instead of it would NOT be fatiguing the LCD. FFS that totally flopped the meaning ![]()
Last edited by MamiyaOtaru (2008-10-17 6:24:15 am)
Offline
Hey Albkwan, excellent work.
One little thing you could do to simplify your script. You can use the 'let' to do arithmetic on variables. So you could change your code that combines the different music states to something like:
let MUSIC_APP_STATE=${MUSIC_APP_STATE_1}+${MUSIC_APP_STATE_2}+${MUSIC_APP_STATE_3}+${MUSIC_APP_STATE_4}+${MUSIC_APP_STATE_5}+${MUSIC_APP_STATE_6}Then ${MUSIC_APP_STATE} will be equal to 0 if nothing is running, or say 3 if xmms, mpg321 and amarokapp are all running.
Hey MamiyaOtaru.
I'm currently running my eee on the AC adaptor with the battery removed, the lid closed and an external monitor. It currently much cooler than when I run it open from the battery with no external monitor.
Mue
Offline
I have added these scripts to the wiki: Howto: Shut down on lid close
Offline
Hey guys I'm sorta new to this. Would be the first code I've made.
I have attempted to combine a few features of the above scripts and wish to achieve the following:
1. When I am playing music, running on batteries, closing the lid would just suspend the screen and come back when I open the lid.
2. When I am at home, I always have it plugged into the mains, if I have yet to plug the vga cable, it would shutdown upon closing
to charge the batteries.
3. When I am at home and have plugged in the vga cable, closing would turn off laptop display and switch to external monitor at 1280x1024.
When i open i want the laptop dispaly to come back.
I think that covers it.
Here's the script I created. Please provide feedback. I don't think it works. I tried it once and my laptop froze.
#!/bin/sh
LID_STATE=`cat /proc/acpi/button/lid/LID/state | awk '{print $2 }'`
PWR_STATE=`cat /proc/acpi/ac_adapter/AC0/state | awk '{print $2 }'`
VGA_STATE=`xrandr --prop -display :0.0 | grep "VGA connected [0-9]" | wc -l`
MUSIC_APP_STATE=`ps -A | egrep "amarokapp|audacious|wxvlc|mplayer|mpg321|xmms" | wc -l`
if [ $LID_STATE = "closed" ] ; then
if [ $PWR_STATE = "on-line" ] ; then
if [ $VGA_STATE = "1" ] ; then
xrandr -display :0.0 --output LVDS --off
xrandr -display :0.0 --output VGA --mode 1280x1024
else
/sbin/fastshutdown.sh
fi
else
if [ $MUSIC_APP_STATE = "0" ] ; then
/etc/acpi/suspend2ram.sh
else
DISPLAY=:0 xset dpms force suspend
fi
else
if [ $VGA_STATE = "1" ] ; then
xrandr -display :0.0 --output LVDS --mode 800x480
xrandr -display :0.0 --output VGA --mode 1280x1024
else
DISPLAY=:0 xset dpms force on
fi
fi
exit 0
Offline
SunrayDJ wrote:
Here's the script I created. Please provide feedback. I don't think it works. I tried it once and my laptop froze.
#!/bin/sh
LID_STATE=`cat /proc/acpi/button/lid/LID/state | awk '{print $2 }'`
PWR_STATE=`cat /proc/acpi/ac_adapter/AC0/state | awk '{print $2 }'`
VGA_STATE=`xrandr --prop -display :0.0 | grep "VGA connected [0-9]" | wc -l`
MUSIC_APP_STATE=`ps -A | egrep "amarokapp|audacious|wxvlc|mplayer|mpg321|xmms" | wc -l`
if [ $LID_STATE = "closed" ] ; then
if [ $PWR_STATE = "on-line" ] ; then
if [ $VGA_STATE = "1" ] ; then
xrandr -display :0.0 --output LVDS --off
xrandr -display :0.0 --output VGA --mode 1280x1024
else
/sbin/fastshutdown.sh
fi
else
if [ $MUSIC_APP_STATE = "0" ] ; then
/etc/acpi/suspend2ram.sh
else
DISPLAY=:0 xset dpms force suspend
fi
*** fi ***
else
if [ $VGA_STATE = "1" ] ; then
xrandr -display :0.0 --output LVDS --mode 800x480
xrandr -display :0.0 --output VGA --mode 1280x1024
else
DISPLAY=:0 xset dpms force on
fi
fi
exit 0
There is a "fi" missing in this script.
Also, depending on the Eee model you have, you may not be able to reach a display size of 1280x1024 + 800x480 because I think the max size of the virtual display (at least for my 701) is 1680x1680.
Offline
Oh ok. When i do that I jus get the left hand side top of the external monitor on the laptop screen, which is fine. Thanks for that.
I have a 701 as well.
I just tried the script. Works ok when on batts and playing music.
But i plugged in the vga cable and ac and then closed lid...it switched screen to ext. monitor but a whole bunch of apps crashed then it restart itself.
Should I only boot up with the vga cable IN, not plug it is while it is running?
If so, any ideas on a workaround apart from plugging it in pre-boot?
Thanks again
Last edited by SunrayDJ (2008-09-09 8:44:17 am)
Offline