Page 4 of 5 FirstFirst ... 2345 LastLast
Results 31 to 40 of 43

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

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

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

    Quote Originally Posted by Pru View Post
    How can I get it to work with other programs? I really want to be able to use xbindkeys so i can change the mapping of some keys while it's closed (my laptop has -some- exposed keys)

    I also tried running stuff like firefox and xfce4-terminal to open when i open the lid and that doesn't work either.


    btw thanks for the great tutorial (i have the starcraft sounds )
    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)

  2. #32
    Join Date
    Dec 2007
    Location
    Galway, Ireland
    Beans
    316
    Distro
    Ubuntu 10.04 Lucid Lynx

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

    Quote Originally Posted by KIAaze View Post
    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)
    I don't think this is enough. Some people might notice that things some times work or some commands will not work.
    It is important to understand that the lid event is managed by the acpid deamon which is owned by root. Anything you run from that /etc/acpi/lid.sh scripts will be run by root. Just running GUI things on DISPLAY:0 might not be enough for some programs or commands that rely on other user environment variables. For example the purple-remote command (which uses dbus) to change your pidgin status from command line will not work, aplay will not work either. So you need to do a bit more to expose your user's environment.
    If anyone is interested I wrote a tutorial which covers what's already covered on this tutorial for the lid open/close events but also includes a fix for the root stuff I just mentioned and it also covers how to do stuff when you dock/undock your computer.

    Cheers!

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

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

    Thanks. I added a link to your howto in the initial post.

    By the way, you should fix your howto a bit.
    There are some unclosed [code] tags:

    [code]#!/bin/bash
    #This runs so that root can run the following command under the user's environment
    source /home/your_user/.Xdbus
    #play a sound
    DISPLAY=:0.0 su your_user -c "aplay /usr/lib/openoffice/basis3.0/share/gallery/sounds/falling.wav"
    [code]#!/bin/bash
    #This runs so that root can run the following command under the user's environment
    source /home/your_user/.Xdbus
    #play a sound
    DISPLAY=:0.0 su your_user -c "aplay /usr/lib/openoffice/basis3.0/share/gallery/sounds/sparcle.wav"
    Last edited by KIAaze; March 4th, 2009 at 09:09 AM. Reason: spelling

  4. #34
    Join Date
    Dec 2007
    Location
    Galway, Ireland
    Beans
    316
    Distro
    Ubuntu 10.04 Lucid Lynx

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

    Quote Originally Posted by KIAaze View Post
    By the way, you should fix yout howto a bit.
    There are some unclosed [code] tags:
    Wow. I haven't noticed. Thanks for letting me know!

  5. #35
    Join Date
    Feb 2011
    Beans
    23

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

    Nice idea! I loved it, except that the closing sound plays both when I open and close the lid... any suggestions?

    EDIT: Realized it myself. In the command line applying grep, I had to change the directory LID for LID0.
    Last edited by erick404; May 29th, 2011 at 03:31 AM.

  6. #36
    Join Date
    Nov 2010
    Location
    India
    Beans
    241
    Distro
    Ubuntu 10.04 Lucid Lynx

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

    lol... kinda reminds me of nite rider... my lids going crazy!! nice 'un!

  7. #37
    Join Date
    May 2011
    Location
    Golden, CO
    Beans
    95
    Distro
    Ubuntu 12.04 Precise Pangolin

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

    What am I missing to make this work? Does it involve not being the root user?

    This is my current lid.sh

    Code:
    #!/bin/bash
    # TODO:  Change the above to /bin/sh
    
    grep -q closed /proc/acpi/button/lid/LID/state
    if [ $? = 0 ]
    then
        aplay /etc/acpi/cartman.wav;
    else
        aplay /etc/acpi/myniga.wav;
    fi 
    
    test -f /usr/share/acpi-support/state-funcs || exit 0
    
    . /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
    Ubuntu 12.04 for personal use
    Solaris 9, 10 and Red Hat Ent 5 @ work

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

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

    Try running lid.sh directly from a terminal and check for any error output.
    If necessary run it with sudo.

  9. #39
    Join Date
    May 2011
    Location
    Golden, CO
    Beans
    95
    Distro
    Ubuntu 12.04 Precise Pangolin

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

    typed ./lid.sh into terminal got the following"

    grep: /proc/acpi/button/lid/LID/state: No such file or directory
    aplay: test_wavefile:876: can't play WAVE-file format 0x0055 which is not PCM or FLOAT encoded

    The same happens running with sudo

    I'd also like to add this is on a fresh 11.04 install... I don't currently have an internet connection that I'm permitted to hook my netbook up to in order to get any of the updates.
    Last edited by sectshun8; May 29th, 2011 at 01:38 PM.
    Ubuntu 12.04 for personal use
    Solaris 9, 10 and Red Hat Ent 5 @ work

  10. #40
    Join Date
    Feb 2007
    Location
    perdita
    Beans
    1,622
    Distro
    Ubuntu

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

    For the grep error, check if you have LID0 instead of LID like erick404.
    i.e. You should have "/proc/acpi/button/lid/LID0/state" or something similar somewhere.

    For the aplay error, it looks like aplay can't play your soundfile, so try to convert it to a compatible format or just use mplayer:

    So your code could be changed like this for instance:
    Code:
    grep -q closed /proc/acpi/button/lid/LID0/state
    if [ $? = 0 ]
    then
        mplayer /etc/acpi/cartman.wav;
    else
        mplayer /etc/acpi/myniga.wav;
    fi
    mplayer is in the repositories and supports mp3s.
    Code:
    sudo apt-get install mplayer
    For converting sound files, you can use ffmpeg I think, but I don't have that much experience with it.

Page 4 of 5 FirstFirst ... 2345 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
  •