Skip to content

Instantly share code, notes, and snippets.

@zhulik
Last active May 12, 2025 20:06
Show Gist options
  • Save zhulik/5f106addffaec4f90b11c5f94242bbc1 to your computer and use it in GitHub Desktop.
Save zhulik/5f106addffaec4f90b11c5f94242bbc1 to your computer and use it in GitHub Desktop.
A script to switch between two monitors and a TV for a Plasma Desktop
#!/bin/ruby
require 'json'
LG = "DP-1"
BENQ = "DP-2"
TV = 'HDMI-A-1'
def switch_monitor(name, state) = `kscreen-doctor output.#{name}.#{state ? 'enable' : 'disable'}`
active = JSON.parse(`kscreen-doctor -j`, symbolize_names: true)[:outputs].find{ _1[:enabled] }[:name]
if active == TV
switch_monitor(LG, true)
switch_monitor(BENQ, true)
switch_monitor(TV, false)
else
switch_monitor(TV, true)
switch_monitor(LG, false)
switch_monitor(BENQ, false)
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment