LinuxQuestions.org
Visit Jeremy's Blog.
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - Software
User Name
Password
Linux - Software This forum is for Software issues.
Having a problem installing a new program? Want to know which application is best for the job? Post your question in this forum.

Notices


Reply
  Search this Thread
Old 06-03-2016, 02:24 PM   #1
Nate5700
LQ Newbie
 
Registered: Jun 2016
Posts: 4

Rep: Reputation: Disabled
Question Command Line Tool for Getting Data on Connected Monitor?


Hello LQ, this is my first time posting though I've often found answers to my questions here before.

So, here's some background. I'm running Debian Jessie inside a chroot using Crouton on my HP Chromebook 14, using KDE as my default window manager. I wrote some simple bash scripts that use xrandr to manipulate the screens when I run certain applications, for example:

Code:
#!/bin/bash

if [ "$(xrandr -q | grep " connected" | grep "HDMI2" | wc -l)" == "1" ]
  then
    xrandr --output eDP1 --off
    xrandr --output HDMI2 --mode 1280x720
fi
vlc
if [ "$(xrandr -q | grep " connected" | grep "HDMI2" | wc -l)" == "1" ]
  then
    xrandr --output eDP1 --auto
    xrandr --output HDMI2 --right-of eDP1
    xrandr --output HDMI2 --auto
fi

exit 0
Basically what this does is detects if I have a monitor connected to my HDMI output and if so it turns off the laptop screen and runs VLC in the 1280x720 mode on the connected screen, then reverts when I exit VLC.

So here's where the question comes: I also have an HDMI/VGA converter that I can use with an old VGA monitor I have laying around, but that monitor doesn't support the 1280x720 resolution mode. So, I would like to be able to have my script detect which monitor is connected and modify its behavior accordingly.

Here's where it gets challenging: Web searches turned up that I can read Xorg.0.log to do this, but as I said before, I'm inside a chroot on my Chromebook and I don't actually have an Xorg.0.log file. Is there some other way, such as a command line tool, for me to read data about my connected monitor?

Thanks in advance for any info you guys can provide!
 
Old 06-03-2016, 06:10 PM   #2
Upuetz
Member
 
Registered: May 2016
Location: Aachen
Distribution: Debian, CentOS, Ubuntu, Raspian, tinycore
Posts: 59

Rep: Reputation: Disabled
Hi,
two options come to mind:
a) have a script copy over the xorg logfile into your chroot. Should be fairly simple ;-)
b) DDC could be used. If you normally have your normal monitor connected you can probably read out the model/brand. With the hdmi/vga connector that info probably get's lost and hence you can differenciate by that.
Maybe these tools/posts help:
http://jaffar.cs.msu.su/oleg/ddcci/
http://stackoverflow.com/questions/2...x-using-libdrm
https://github.com/rockowitz/ddctool

HTH,
Upuetz

Last edited by Upuetz; 06-03-2016 at 06:14 PM.
 
Old 06-03-2016, 06:17 PM   #3
KenJackson
Member
 
Registered: Jul 2006
Location: Maryland, USA
Distribution: Fedora and others
Posts: 757

Rep: Reputation: 145Reputation: 145
You could try the monitor-edid tool. It reads the monitor's EDID data.
Fedora has a package by the same name, I would expect Debian to also.
 
Old 06-03-2016, 07:50 PM   #4
Nate5700
LQ Newbie
 
Registered: Jun 2016
Posts: 4

Original Poster
Rep: Reputation: Disabled
Thanks for your replies guys. It looks like both of you are going the same direction in suggesting tools that read out the monitor's EDID.

Debian doesn't seem to have a package called "monitor-edid" but it does have "read-edid", maybe it's the same thing? In any case, I played with it in the terminal and it gives outputs that can differentiate between the two monitors, so I should be able to figure out a way to write my script to take advantage of that. Only issue though is that you have to run it with root permissions for it to work properly, and I'd prefer not to have to run my script as root.

I tried the DDC tool but can't seem to get it to work (I get output that says "Invalid filename (/dev/i2c-9)").

I'll dig a little more and see if I can find a solution to the root permissions problem, if someone here already has an idea I'm open. I'll post back if I find something.
 
Old 06-03-2016, 08:16 PM   #5
descendant_command
Senior Member
 
Registered: Mar 2012
Posts: 1,873

Rep: Reputation: 643Reputation: 643Reputation: 643Reputation: 643Reputation: 643Reputation: 643
You could set up passwordless sudo for that particular command.
 
Old 06-04-2016, 12:40 AM   #6
Nate5700
LQ Newbie
 
Registered: Jun 2016
Posts: 4

Original Poster
Rep: Reputation: Disabled
Ok, so I got a couple of scripts written, one is run as root and contains the commands for the "read-edid" tools. The other runs VLC. The root script runs in the background and when the VLC script is run the root script executes based on a process I found here, see the top answer: http://askubuntu.com/questions/20971...-a-bash-script

Here are the scripts if anyone's interested:

Root script:
Code:
#!/bin/bash

while :
  do
    inotifywait -q -q -e modify "/home/nathan/.scripts/monitorscript" > /dev/null

    if [ "$(cat /home/nathan/.scripts/monitorscript)" == "vlc" ]
      then
        x=$(get-edid -q -b 7 | parse-edid | grep "DisplaySize" | tr -d A-z | column -t | awk '{print $1}')
        y=$(get-edid -q -b 7 | parse-edid | grep "DisplaySize" | tr -d A-z | column -t | awk '{print $2}')
        r=$(echo "scale=3; $x/$y" | bc)

        if [ "$(xrandr -q | grep " connected" | grep "HDMI2" | wc -l)" == "1" ] && (( $(echo "$r >= 1.777" | bc) ))
          then
            echo "16x9" > /home/nathan/.scripts/vlcscript
          else
            if [ "$(xrandr -q | grep " connected" | grep "HDMI2" | wc -l)" == "1" ]
              then
                echo "4x3" > /home/nathan/.scripts/vlcscript
              else
                echo "NoHDMI" > /home/nathan/.scripts/vlcscript
            fi
        fi
    fi
  done

exit 0
User script:
Code:
#!/bin/bash

echo "vlc" > .scripts/monitorscript
inotifywait -q -q -e modify ".scripts/vlcscript" > /dev/null
if [ "$(cat .scripts/vlcscript)" == "16x9" ]
  then
    xrandr --output eDP1 --off
    xrandr --output HDMI2 --mode 1280x720
  else
    if [ "$(cat .scripts/vlcscript)" == "4x3" ]
      then
        xrandr --output eDP1 --off
    fi
fi
vlc
if [ "$(cat .scripts/vlcscript)" == "16x9" ] || [ "$(cat .scripts/vlcscript)" == "4x3" ]
  then
    xrandr --output eDP1 --auto
    xrandr --output HDMI2 --right-of eDP1
    xrandr --output HDMI2 --auto
fi

exit 0
Works like a champ, so I think we can mark this as "solved".
 
Old 06-04-2016, 02:15 AM   #7
KenJackson
Member
 
Registered: Jul 2006
Location: Maryland, USA
Distribution: Fedora and others
Posts: 757

Rep: Reputation: 145Reputation: 145
Both the root and user scripts modify the same file. That could cause a permission problem. I would suggest writing separate files, maybe /usr/local/etc/vlcscript for root.
 
Old 06-04-2016, 03:13 AM   #8
Nate5700
LQ Newbie
 
Registered: Jun 2016
Posts: 4

Original Poster
Rep: Reputation: Disabled
They should be writing to different files...the root script writes to "vlcscript" and the user script writes to "monitorscript". I probably should comment those scripts to make things clearer.
 
  


Reply


Thread Tools Search this Thread
Search this Thread:

Advanced Search

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off



Similar Threads
Thread Thread Starter Forum Replies Last Post
Command Line search tool alsaf Linux - Newbie 4 04-11-2011 11:50 AM
How to use a command line tool? LAPIII Linux - Software 1 03-21-2011 03:12 PM
command-line tool to get email MTK358 Linux - Software 9 12-09-2009 05:16 PM
Simple tool to monitor real-time bandwidth usage of all connected hosts on LAN? mattp52 Linux - Networking 5 02-13-2008 11:18 PM
where is the ffmpeg command line tool? leodemario Linux - Desktop 5 02-25-2007 03:11 PM

LinuxQuestions.org > Forums > Linux Forums > Linux - Software

All times are GMT -5. The time now is 08:04 AM.

Main Menu
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Open Source Consulting | Domain Registration