How To Switch On Your Black Screen: Shortcut & Script

Write tutorials here
There are more tutorials here http://community.linuxmint.com/tutorial/welcome
Forum rules
Please don't add support questions to tutorials,start your own thread in the appropriate sub-forum instead. Before you post please read this
Post Reply
User avatar
sebastjava
Level 1
Level 1
Posts: 38
Joined: Wed Jun 28, 2017 8:01 pm
Location: Montréal
Contact:

How To Switch On Your Black Screen: Shortcut & Script

Post by sebastjava » Thu Feb 08, 2018 5:05 pm

Do you get a black screen when your computer resumes from suspend? The screen is off and it is damn awkward. If you are lucky enough to know which command to use to turn it back on, you can't do that, because you can't see anything! This tutorial will show you how to solve this. We can have a simple keyboard shortcut to turn on the screen, or we can have it done automatically.

I have a little Asus Eee PC X101CH. I had this problem with Linux Mint Xfce 18.2 installed. I don't have this problem anymore since i installed Linux Mint MATE 18.2. But you can try what follows if you are stuck with a black screen on resume from suspend. Like when you simply close the lid and re-open it.


FIRST, MAKE A SIMPLE KEYBOARD SHORTCUT

Get your monitor's name by typing xrandr --listactivemonitors in your terminal. Example:

Code: Select all

username@computername ~ $ xrandr --listactivemonitors
Monitors: 1
 0: +*LVDS-1 1024/223x600/125+0+0  LVDS-1
In this example, the monitor's name is LVDS-1. Remember your monitor's name.
  1. Go to: Start Menu > Preferences > Keyboard Shortcuts
  2. Click Add
  3. Name it "Screen ON" and enter this command: /usr/bin/xrandr --output LVDS-1 --auto
    (Change "LVDS-1" to your monitor's name.)
  4. Click Apply
  5. Click over "Disabled" and press Ctrl+F7
  6. Close
Now, test it. Save all your opened files and close everything, because if it does not work you will have to restart your computer. Ready? Open a terminal and turn off the screen with this command: xrandr --output LVDS-1 --off. (Change "LVDS-1" to your monitor's name.) Pressing Ctrl+F7 should get you out of trouble.

That was all you needed. But if you want to make things more pleasant, do what follows.


GET YOUR SCREEN TURNED ON AUTOMATICALLY
  1. Copy the script named "01-SCREEN-ON.SH" listed at the bottom of this page.
  2. Paste it into a simple text editor, not into a big word processor.
  3. Change "USERNAME" to your user name.
  4. Get your monitor's name by typing xrandr --listactivemonitors in your terminal. Example:

    Code: Select all

    username@computername ~ $ xrandr --listactivemonitors
    Monitors: 1
     0: +*LVDS-1 1024/223x600/125+0+0  LVDS-1
    In this example, the monitor's name is "LVDS-1".
  5. In your script, change every "LVDS-1" to your monitor's name.
  6. Save your script in plain text format and name it with ".sh" extension, like this: "01-screen-on.sh".
  7. Open this folder as administrator (right-click to do so): /usr/lib/pm-utils/sleep.d/
  8. Place a copy of your "01-screen-on.sh" script in this folder.
  9. In your file manager, in that same folder, right-click on your script's icon to edit properties. Select "Permissions" tab and click on "Execute" to allow executing file as program.
  10. Restart your computer.
Test it! Close and re-open the lid. If the screen is not switched on automatically, you still have your handy keyboard shortcut to get you out of trouble.


TROUBLESHOOTING:
  1. /usr/lib/pm-utils/sleep.d/ might not be the right folder. There is a folder where the system will execute all the scripts on resume from suspend, but that folder might be somewhere else depending on your system's version. Search the web on this subject.
  2. Make sure you have /usr/share/sounds/linuxmint-login.wav and /usr/share/sounds/linuxmint-gdm.wav files. If not, replace them with some other sound. Those sounds are required. They help you know what is going on and they insert a required delay.
  3. Make sure you have all the commands installed: sleep, xrandr & aplay.
  4. Read all this tutorial again.
01-SCREEN-ON.SH

Code: Select all

#!/bin/bash
# This script should power on your screen on resume from suspend.
# It was used with Linux Mint Xfce 18.2 on my Asus Eee PC X101CH.
#
# Lots of things are happening on resume from suspend. Screen is first
# turned on and back off. So this scripts starts with a sleep, then
# goes into a loop: sleep, check, exit or try to switch on, loop...
# Created by SebastJava with some inputs from dro0g, sdennie & swissz:
# https://ubuntuforums.org/showthread.php?t=1190894

case "$1" in
resume)
	sleep 3
	export DISPLAY=:0
	export XAUTHORITY=/home/USERNAME/.Xauthority

	for var in 1 2 3 4 5 6 7 8 9 10; do
		sleep 1
		if (xrandr --listactivemonitors|grep LVDS-1); then
			aplay /usr/share/sounds/linuxmint-login.wav
			echo "The monitor is active."; exit 0
		else
			xrandr --output LVDS-1 --auto --brightness 1.0
			aplay /usr/share/sounds/linuxmint-gdm.wav
			echo "XRANDR is trying to activate the monitor..."
		fi
	done
;;
esac
exit 0

Post Reply

Return to “Tutorials”