Can I detect the presence of a second display in a shell script or Conky config?

3

I want to modify my conky placement depending on whether I'm working with my laptop in my lap (one screen) or have it at my desk attached to a larger monitor (dual display).

The problem is that I want it to appear on the bottom left of my laptop screen no matter what. But with my dual display setup, the "bottom left" happens to be on my external monitor.

It seems like there are two solutions:

  • Add an if/else statement to the script I use to launch conky (conky.sh) that launches a different config file depending on my display arrangement.

  • Add an if/else statement to my conky config that sets either the alignment or an indentation value depending on the display arrangement.

(And yes, I realize that at least the shell version only works if I've got things plugged/unplugged when I launch conky. I can live with that.

But ... I don't even know how to detect a dual display or a second monitor in bash or conky.

Amanda

Posted 2013-11-30T19:04:20.893

Reputation: 242

Did you ever get this working? If so, can you share your conky config? – crypdick – 2017-11-12T17:19:54.240

Answers

3

Nathan's suggestion above will give the same result under all circumstances as the xrandr command gives information about all display outputs (connected/disconnected).

This code will work:

$ xrandr | grep -sw 'connected' | wc -l

Note: Not my idea. I just merged Nathan's suggestion and this.

Benc Marek

Posted 2013-11-30T19:04:20.893

Reputation: 31

In this case, you don't need the -s flag (or the single quotes). – Anthony Geoghegan – 2016-10-27T08:54:37.707

1

You can use xrandr and grep to detect the connected monitors. Then use wc -l to count the number of lines returned.

Try this in the terminal:

xrandr | grep connected | wc -l

Nathan Lippi

Posted 2013-11-30T19:04:20.893

Reputation: 121