How to re-enable a monitor via command ine

6,296

Here are a few lines from my .bash_alias file, you would be most interested in the laptop command:

# switch between dual screen and laptop screen...
_vga=$( xrandr  | sed -n 's/^\(VGA.\).*/\1/pg')
alias laptop='xrandr --output LVDS1 --auto --output $_vga --off'
alias monitor='xrandr --output LVDS1 --off --output $_vga --auto'
alias dual='xrandr --output LVDS1 --auto --left-of $_vga --output $_vga --auto'

So, if your laptop's screen is eDP1, you can enable it with:

xrandr --output eDP1 --auto

While you could bind this to a udev rule, I suggest you simply bind it to a shortcut key which you can run when the screen dies on you.

Share:
6,296

Related videos on Youtube

Louis Kröger
Author by

Louis Kröger

Updated on September 18, 2022

Comments

  • Louis Kröger
    Louis Kröger over 1 year

    To give some background, I almost exclusively use docking stations with my laptop. I have a few monitors connected to the docking station and always have my laptop closed when in this configuration. In addition, since the laptop is closed, I also disable the monitor in the Display manager.

    The problem is that if I remove the laptop from the docking station the monitor will remain off. This tends to happen either if I have suspended the OS prior to removal or not. It only sometimes happens, to make things more difficult, and I have no information regarding any possible triggers that may cause it since I cannot access the machine in this state. I have not gone so far as to ssh into it. I am, however, able to remount the laptop to the docking station and drive the external monitors as expected when in this state.

    Are there any known problems with something like this in Mint?


    tl;dr Is there a method to re-enable the laptop's main (integrated) monitor via command line? I could bind this to some kind of key combination or udev rule possibly.

    Edit

    xrandr output with no external monitors connected and dislocated from the docking station

    Screen 0: minimum 320 x 200, current 1920 x 1080, maximum 32767 x 32767
    eDP1 connected primary 1920x1080+0+0 (normal left inverted right x axis y axis) 344mm x 193mm
       1920x1080      60.0*+   59.9     48.0  
       1680x1050      60.0     59.9  
       1600x1024      60.2  
       1400x1050      60.0  
       1280x1024      60.0  
       1440x900       59.9  
       1280x960       60.0  
       1360x768       59.8     60.0  
       1152x864       60.0  
       1024x768       60.0  
       800x600        60.3     56.2  
       640x480        59.9  
    VGA2 disconnected (normal left inverted right x axis y axis)
    HDMI1 disconnected (normal left inverted right x axis y axis)
    DP1 disconnected (normal left inverted right x axis y axis)
    HDMI2 disconnected (normal left inverted right x axis y axis)
    DP2 disconnected (normal left inverted right x axis y axis)
    

    HDMI3 disconnected (normal left inverted right x axis y axis) VIRTUAL1 disconnected (normal left inverted right x axis y axis) VGA-1-0 disconnected

    • terdon
      terdon over 8 years
      Yes, this can be easily scripted using xrandr. Please edit your question and show us the output of xrandr when docked. When you do, make sure to explain which screen is which.
    • Louis Kröger
      Louis Kröger over 8 years
      @terdon, updated. The output corresponds to no externally connected monitors; only the laptops integrated monitor is connected.
    • terdon
      terdon over 8 years
      OK, then see Jacob Minshall's updated answer. xrandr --output eDP1 --auto should do it.