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


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.



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.42, acpid 2.0.30, coreutils 8.30 and Bash 4.4.23 on Fedora 29 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.2.zip && cd vt-lock-0.9.2
  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]




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.


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.


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