Page 1 of 5 123 ... LastLast
Results 1 to 10 of 43

Thread: How to make your laptop play sounds on lid open/close :)

  1. #1
    Join Date
    Feb 2007
    Location
    perdita
    Beans
    1,625
    Distro
    Ubuntu

    How to make your laptop play sounds on lid open/close :)

    Main howto:
    Have you ever wanted your laptop to act like a Starcraft tank?
    Well, with Ubuntu it's possible and very easy to do.

    Whenever the lid of your laptop is opened or closed, Ubuntu runs the /etc/acpi/lid.sh script.
    This script determines if the lid is open or closed by looking at the contents of "/proc/acpi/button/lid/LID/state".

    So all you have to do to play opening/closing sounds is add this after the "#!/bin/bash" line:

    Code:
    grep -q closed /proc/acpi/button/lid/LID/state
    if [ $? = 0 ]
    then
            aplay /etc/acpi/closing.wav;
    else
            aplay /etc/acpi/opening.wav;
    fi
    where closing.wav and opening.wav are the sound files I use, placed in /etc/acpi.

    Here's my complete lid.sh file:
    Code:
    #!/bin/bash
    
    grep -q closed /proc/acpi/button/lid/LID/state
    if [ $? = 0 ]
    then
    	aplay /etc/acpi/closing.wav;
    else
    	aplay /etc/acpi/opening.wav;
    fi
    
    . /usr/share/acpi-support/power-funcs
    . /usr/share/acpi-support/policy-funcs
    . /etc/default/acpi-support
    
    [ -x /etc/acpi/local/lid.sh.pre ] && /etc/acpi/local/lid.sh.pre
    
    if [ `CheckPolicy` == 0 ]; then exit; fi
    
    grep -q closed /proc/acpi/button/lid/*/state
    if [ $? = 0 ]
    then
        for x in /tmp/.X11-unix/*; do
    	displaynum=`echo $x | sed s#/tmp/.X11-unix/X##`
    	getXuser;
    	if [ x"$XAUTHORITY" != x"" ]; then
    	    export DISPLAY=":$displaynum"	    
    	    . /usr/share/acpi-support/screenblank
    	fi
        done
    else
        for x in /tmp/.X11-unix/*; do
    	displaynum=`echo $x | sed s#/tmp/.X11-unix/X##`
    	getXuser;
    	if [ x"$XAUTHORITY" != x"" ]; then
    	    export DISPLAY=":$displaynum"
    	    grep -q off-line /proc/acpi/ac_adapter/*/state
    	    if [ $? = 1 ]
    		then
    		if pidof xscreensaver > /dev/null; then 
    		    su $user -c "xscreensaver-command -unthrottle"
    		fi
    	    fi
    	    if [ x$RADEON_LIGHT = xtrue ]; then
    		[ -x /usr/sbin/radeontool ] && radeontool light on
    	    fi
    	    if [ `pidof xscreensaver` ]; then
    		su $user -c "xscreensaver-command -deactivate"
    	    fi
    	    su $user -c "xset dpms force on"
    	fi
        done
    fi
    [ -x /etc/acpi/local/lid.sh.post ] && /etc/acpi/local/lid.sh.post
    If you have Starcraft, you can extract the game sounds using the sound utilities available here: http://www.battle.net/files.shtml
    The sound files for the tank are ttatra00.wav and ttatra01.wav.

    Additional remarks:
    Note 1:
    It is of course possible to run any command on lid open/close events.
    If you have other fun or useful ideas of what a laptop should do on lid events, please post them here.
    (Sleep and hibernate isn't original. )

    I was thinking about a switch into full download mode on lid close, so that your PC automatically starts using bandwidth for P2P for example when you aren't using it. ^^
    I just don't know how to do that by command-line yet.

    Note 2: How to run scripts for laptop lid open/close and dock/undock events:
    Please refer to the howto from lunatico here:
    [HOWTO] Run scripts for laptop lid open/close and dock/undock events

    Note 3: How to run GUIs:
    [edit]
    cf note above which is a better way to do it.
    [/edit]

    I found a way to do it.
    To run a GUI as root:
    Code:
    DISPLAY=:0 && command
    To run a GUI as normal user:
    Code:
    DISPLAY=:0 && sudo -u username command
    And for those interested in running GUI apps from root crontab, here's how:
    To run a GUI from root crontab as root:
    Code:
    XAUTHORITY=/home/username/.Xauthority
    DISPLAY=:0.0
    
    # m h  dom mon dow   command
    * * * * * sudo -u username command
    To run a GUI from root crontab as normal user:
    Code:
    XAUTHORITY=/home/username/.Xauthority
    DISPLAY=:0.0
    
    # m h  dom mon dow   command
    * * * * * command
    Useful links:
    http://www.faqs.org/docs/Linux-mini/Remote-X-Apps.html
    A script to launch another xserver and run a command on it:
    http://ubuntuforums.org/showthread.php?t=699332
    (basically, use "chvt <tty nb>" and then DISPLAY=... && command)

    Note 3: Synthetizing voice
    You can use "espeak" or "festival" for this.
    Code:
    espeak "hello"
    Code:
    echo "hello" | festival --tts
    To read a whole text file:
    Code:
    festival --tts speak.txt
    Note 4: make the console acknowledge each of your commands with an audio sound
    I don't think this deserves its own howto (would need a full .bashrc tutorial), but this might also interest some people: make the console acknowledge each of your commands with an audio sound.

    Again, RTS sounds are the best for this.
    "By your command..."

    Original post: http://ubuntuforums.org/showpost.php...2&postcount=61

    ================================================== ======

    If you want to play sounds in your terminal when running any command (or just pressing enter), do the following:

    Open ~/.bashrc.
    Search for a string looking like "PS1=<some string>".
    Add "\$(playsound)" at the beginning of the string.
    It should then look like this for example:
    Code:
    PS1="\$(playsound)\e[0;1;33;41m[\u@\h:\w]\$ \e[m "
    Then before that (at the beginning of the file), add:
    Code:
    playsound()
    {
    	aplay somefile.wav 1>/dev/null 2>&1 &
    }
    Note the "&" at the end of the aplay command to avoid having to wait for the end of the soundfile playing.
    It also makes spamming possible when pressing enter several times.

    example:"NuNuNuclear lalalaunch detectededed."

    Some documentation:
    http://www.linuxselfhelp.com/howtos/...O-2.html#setps
    http://tldp.org/HOWTO/Bash-Prompt-HOWTO/x279.html
    ================================================== ======
    Last edited by KIAaze; September 19th, 2009 at 06:30 PM. Reason: replaced mplayer with aplay

  2. #2
    Join Date
    May 2007
    Location
    Amsterdam
    Beans
    28
    Distro
    Ubuntu 7.04 Feisty Fawn

    Re: How to make your laptop play sounds on lid open/close :)

    Nice, I like the idea... the possibilities are endless, to speak in sale-terms ;_)

    but yeah, cool stuff can be done with it.

  3. #3
    Join Date
    Feb 2007
    Location
    perdita
    Beans
    1,625
    Distro
    Ubuntu

    Re: How to make your laptop play sounds on lid open/close :)

    I don't think this deserves its own howto (would need a full .bashrc tutorial), but this might also interest some people: make the console acknowledge each of your commands with an audio sound.

    Again, RTS sounds are the best for this.
    "By your command..."

    Original post: http://ubuntuforums.org/showpost.php...2&postcount=61

    ================================================== ======
    Quote Originally Posted by justin whitaker View Post
    6. Each terminal command receives an audible response of "as you command dread lord."
    Ok, I did it.
    If you want to play sounds in your terminal when running any command (or just pressing enter), do the following:

    Open ~/.bashrc.
    Search for a string looking like "PS1=<some string>".
    Add "\$(playsound)" at the beginning of the string.
    It should then look like this for example:
    Code:
    PS1="\$(playsound)\e[0;1;33;41m[\u@\h:\w]\$ \e[m "
    Then before that (at the beginning of the file), add:
    Code:
    playsound()
    {
    	mplayer somefile.wav 1>/dev/null 2>&1 &
    }
    Note the "&" at the end of the mplayer command to avoid having to wait for the end of the soundfile playing.
    It also makes spamming possible when pressing enter several times.

    example:"NuNuNuclear lalalaunch detectededed."

    Some documentation:
    http://www.linuxselfhelp.com/howtos/...O-2.html#setps
    http://tldp.org/HOWTO/Bash-Prompt-HOWTO/x279.html
    ================================================== ======

  4. #4
    nikoPSK is offline I Ubuntu, Therefore, I Am
    Join Date
    Sep 2007
    Location
    Victoria, BC
    Beans
    2,265
    Distro
    Ubuntu 8.04 Hardy Heron

    Re: How to make your laptop play sounds on lid open/close :)

    I like! But, my laptop is soooo slow I dont think it can run linux. Ive tried like 7 distros for it so far.... Any way for my laydown pc to have cool noises say....

    Laptop specs:
    128 RAM
    267 MGz Processor
    heaven knows how much Hard-drive Space....

  5. #5
    Join Date
    Feb 2007
    Location
    perdita
    Beans
    1,625
    Distro
    Ubuntu

    Re: How to make your laptop play sounds on lid open/close :)

    Have you tried the light GNU/Linux distros?:
    -xubuntu (this one may be too heavy)
    -Puppy Linux
    -Feather Linux
    -Damn Small Linux (DSL)
    etc

    DSL has been demonstrated browsing the web with Dillo, running simple games and playing music on systems with a 486 processor and 16MB of RAM.
    Feather should be able to run on a 486 with 16Mb of RAM, but only in console (non-graphical) mode. To use X, 24Mb of RAM or more are required.

  6. #6
    nikoPSK is offline I Ubuntu, Therefore, I Am
    Join Date
    Sep 2007
    Location
    Victoria, BC
    Beans
    2,265
    Distro
    Ubuntu 8.04 Hardy Heron

    Re: How to make your laptop play sounds on lid open/close :)

    I've tried all those and more except feather. Mine has half the processor speed required.

  7. #7
    Join Date
    Jul 2007
    Location
    Bariloche, Argentina
    Beans
    2,140
    Distro
    Xubuntu 13.04 Raring Ringtail

    Re: How to make your laptop play sounds on lid open/close :)

    Sounds nice!! Do I need to have mplayer for doing this? Can't I do it with other players?

  8. #8
    Join Date
    Feb 2007
    Location
    perdita
    Beans
    1,625
    Distro
    Ubuntu

    Re: How to make your laptop play sounds on lid open/close :)

    Anything you can run by command-line should work.

  9. #9
    Join Date
    Jul 2007
    Location
    Bariloche, Argentina
    Beans
    2,140
    Distro
    Xubuntu 13.04 Raring Ringtail

    Re: How to make your laptop play sounds on lid open/close :)

    Quote Originally Posted by santiagoward2000 View Post
    Sounds nice!! Do I need to have mplayer for doing this? Can't I do it with other players?
    Hey, I found hoe to do it with alsa. In case anyone needs it the code is:
    Code:
    alsa "soundfile"

  10. #10
    Join Date
    Jun 2006
    Location
    Gothenburg
    Beans
    142
    Distro
    Ubuntu Jaunty Jackalope (testing)

    Re: How to make your laptop play sounds on lid open/close :)

    Ubuntu 7.10

Page 1 of 5 123 ... LastLast

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •