FedoraForum.org - Fedora Support Forums and Community
Results 1 to 4 of 4
  1. #1
    Join Date
    Nov 2009
    Posts
    17
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    Run a script when laptop lid opens/closes

    I want to automatically run a script when I close my laptop lid, just before it goes to sleep, and also run a script when I open the lid again.

    Some distros have a lid.sh file in /etc/acpi/ that gets run automatically, but I don't see such a file on Fedora. I tried putting a file in /etc/pm/sleep.d/ but apparently those don't get run when closing/opening the lid.

    I saw a couple other threads where people recommended installing gnome-tweak-tool, but I'm using KDE.

    Any suggestions?

  2. #2
    Join Date
    Jul 2009
    Location
    England, UK
    Posts
    969
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    Re: Run a script when laptop lid opens/closes

    I would install the acpid package first. That will create two directories called /etc/acpi/events and /etc/acpi/actions.

    Put a file called lidconf in /etc/acpi/events with these contents:
    Code:
    # run a script on lid open/close events
    event=button/lid
    action=/etc/acpi/actions/lid.sh "%e"
    Now save your script as /etc/acpi/action/lid.sh. The script will receive an argument which will end with "open" or "close" (depending on whether, you guessed it, the lid was opened or closed), so you can test to see which case it is by starting the script with something like:
    Code:
    state=$(echo "$1" | cut -d " " -f 3)
    case "$state" in
        open)
            # do what needs to be done when the lid is opened
            ;;
        close)
            # do what needs to be done when the lid is closed
            ;;
        *)
            # panic: not a state I know about!
    esac
    Once it is configured, you need to enable and start the acpi daemon with
    Code:
    systemctl enable acpid && systemctl start acpid
    Hope that gets you started.

  3. #3
    Join Date
    Nov 2009
    Posts
    17
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    Re: Run a script when laptop lid opens/closes

    Awesome, thanks a ton!

    Just a note in case somebody else runs into this issue: If acpid is already running, apparently you have to kill it and restart it for the changes to take effect.

  4. #4
    Join Date
    Jul 2014
    Location
    Espinho, Portugal
    Age
    42
    Posts
    3
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    Re: Run a script when laptop lid opens/closes

    I'm trying to use this script on fedora 22 to turn the touchpad on and off through gsettings command but it doesn't work, any ideas on how to make it work?

Similar Threads

  1. [SOLVED] Cron opens Konsole on script execution and leaves it open
    By GandalfGraa in forum Using Fedora
    Replies: 2
    Last Post: 16th March 2011, 08:36 PM
  2. mplayer will not run (opens then closes)
    By jbarnett74 in forum Using Fedora
    Replies: 2
    Last Post: 23rd January 2007, 11:07 PM

Tags for this Thread

Posting Permissions

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