Asus Screenpad Management service – Asus UX482EG

descriptionStandard

This post provides a script that can be used in conjunction with systemd to manage and restore the screenpad state when resuming from sleep on Asus laptops with a Screenpad installed.

This has been tested with the Asus UX482EG but it should work with other models.

Table of Contents

    Note that this requires that the package Asus WMI Screenpad is installed.

    Screen Management Script

    The script ran by the screenpad-sleeper.service:

    #!/bin/sh
    
    # Get the current brightness 0 indicates that it is offline
    BRIGHTNESS_FILE="/var/tmp/screenpad_brightness"
    BRIGHTNESS_SYS_FILE="/sys/class/leds/asus::screenpad/brightness"
    
    store_brightness() {
        cat "$BRIGHTNESS_SYS_FILE" > "$BRIGHTNESS_FILE"
    }
    
    restore_brightness() {
        if [ -f "$BRIGHTNESS_FILE" ]; then
            STORED_BRIGHTNESS=$(cat "$BRIGHTNESS_FILE")
            if [ "$STORED_BRIGHTNESS" -gt 0 ]; then
                echo "$STORED_BRIGHTNESS" > "$BRIGHTNESS_SYS_FILE"
                screenpad $STORED_BRIGHTNESS
            else
                screenpad off
            fi
        rm "$BRIGHTNESS_FILE"
        else
            screenpad off
        fi
    }
    
    if [ "$1" = "pre" ]; then
        store_brightness
        screenpad off
    elif [ "$1" = "post" ]; then
        restore_brightness
    fi
    screenpad_wake_helper.shView rawView file on GitLab

    The systemd service:

    [Unit]
    Description=Run helper on wake from sleep; restores screenpad state prior to sleep.
    Before=systemd-suspend.service
    StopWhenUnneeded=yes
    
    [Service]
    Type=oneshot
    RemainAfterExit=yes
    ExecStart=/usr/local/bin/screenpad_wake_helper.sh pre
    ExecStop=/usr/local/bin/screenpad_wake_helper.sh post
    
    [Install]
    WantedBy=sleep.target
    screenpad-sleeper.serviceView rawView file on GitLab