www.voj-tech.net


vt-lock

Synopsis

vt-lock is a simple Bash script which locks the screen when the laptop lid is closed.

Motivation

The script comes in handy when your desktop environment does not provide the functionality already (in my case this was LXDE) or it does but you want to have greater control over what your laptop does.

Installation

Prerequisites

The script requires vt-bash-utils 0.9.0 or later. In particular it calls the function vtbu_single_instance_running. Please download the library from the project page and install it following the instructions provided.

Moreover it is required that your environment features reasonably new versions of:

  • XScreenSaver
  • acpid
  • the GNU core utilities
  • Bash

It should be noted that the script has been tested using XScreenSaver 5.37, acpid 2.0.28, coreutils 8.27 and Bash 4.4.12 on Fedora 26 running on a Lenovo ThinkPad T420 laptop.

Installation Steps

It is currently required to perform a simple manual installation. To do so follow these steps:

  1. Download a ZIP file with the required version of the script from this page. Most likely you want the latest version.

  2. Unpack the downloaded file.

    unzip vt-lock-0.9.1.zip && cd vt-lock-0.9.1
    
  3. If the vt-bash-utils library was installed to a directory other than the /usr/local/share directory modify the vt-lock.sh script on the line where the variable bash_utils_path is assigned a value to specifying the correct directory.

  4. Copy the script to a directory which is in your PATH environment variable and which is your preferred location to install third-party software to. This might be the /usr/local/bin directory for example. Make sure this is done as a user account allowed to write to the destination directory.

    cp vt-lock.sh /usr/local/bin
    
  5. Add the execute mode bit to the script file mode bits. Again, make sure that this is done as the appropriate user account.

    chmod +x /usr/local/bin/vt-lock.sh
    
  6. A common way to enable an application to autostart upon login to a desktop environment is to create a desktop entry for it in one of the directories /usr/xdg/autostart and ~/.config/autostart.

    cat > ~/.config/autostart/vt-lock.sh.desktop <<'EOF'
    [Desktop Entry]
    Type=Application
    Exec=vt-lock.sh
    Hidden=false
    Name=vt-lock.sh
    Comment=
    EOF
    

Reference

Usage

vt-lock.sh

Start vt-lock.

The intention is to configure the desktop environment to do this upon login (see above).

The script currently does not understand any command line options or other arguments.

Description

The script listens for ACPI events and when an event of class button/lid with the value of 'close' occurs it locks the screen by turning on the screensaver.

Currently the script prevents running multiple instances of itself at the same time. Therefore it does not fully support a system shared among multiple users.

Bugs

Suggestions and bug reports are more than welcome at voj-tech@voj-tech.net.