Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
This script prevents lock screen from dimming. Tested on Ubuntu 16.04.2 LTS with default Unity interface.
#!/bin/bash
# Copyright (c) 2017 @yuan3y
# Released under MIT License
# Tested on Ubuntu 16.04.2 LTS with default Unity interface
#
# USAGE:
# chmod +x install_prevent_lock_screen_dim.sh
# ./install_prevent_lock_screen_dim.sh
scriptFile=~/.prevent_lock_screen_dim.sh
desktopFile=~/.config/autostart/.prevent_lock_screen_dim.sh.desktop
if hash xdotool 2>/dev/null; then
echo "Checking xdotool exists: PASS"
else
echo "Checking xdotool exists: FAILED"
while true; do
read -p "Do you wish to install xdotool the commandline X11 automation tool?" yn
case $yn in
[Yy]* ) sudo apt-get install xdotool; break;;
[Nn]* ) exit;;
* ) echo "Please answer yes or no.";;
esac
done
fi
cat > ${scriptFile} <<_EOF
#!/bin/bash
# This script prevents lock screen from dimming while it is running.
#
# Copyright (c) 2017 @yuan3y
# Released under MIT License
# Tested on Ubuntu 16.04.2 LTS with default Unity interface
#
# To uninstall the script,
# # 1) Kill all running instance,
# kill \$(ps aux | grep '[p]revent_lock_screen_dim.sh' | awk '{print \$2}')
# # 2) remove it from Startup Applications, or run the following command
# rm ${desktopFile}
# rm ${scriptFile}
dbus-monitor --session "type='signal',interface='com.ubuntu.Upstart0_6'" |
while read x; do
case "\$x" in
*"started"*) sleep 1; xdotool key "Escape";;
esac
done
_EOF
chmod +x ${scriptFile}
cat > ${desktopFile} <<_EOF
[Desktop Entry]
Type=Application
Exec=${HOME}/.prevent_lock_screen_dim.sh
Hidden=false
NoDisplay=false
X-GNOME-Autostart-enabled=true
Name=Prevent Lock Screen Dimming
Comment=Preventing Lock Screen from Dimming
_EOF
${scriptFile} &>/dev/null &
echo "Installation is done. Your lock screen will be prevented from dimming."
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment