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:
- the GNU core utilities
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.
It is currently required to perform a simple manual installation. To do so follow these steps:
Download a ZIP file with the required version of the script from this page. Most likely you want the latest version.
Unpack the downloaded file.
unzip vt-lock-0.9.2.zip && cd vt-lock-0.9.2
If the vt-bash-utils library was installed to a directory other than the
/usr/local/sharedirectory modify the
vt-lock.shscript on the line where the variable
bash_utils_pathis assigned a value to specifying the correct directory.
Copy the script to a directory which is in your
PATHenvironment variable and which is your preferred location to install third-party software to. This might be the
/usr/local/bindirectory 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
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
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
cat > ~/.config/autostart/vt-lock.sh.desktop <<'EOF' [Desktop Entry] Type=Application Exec=vt-lock.sh Hidden=false Name=vt-lock.sh Comment= EOF
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
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 email@example.com.