Page 1 of 1

measur3r script modified to give inch/cm units

Posted: Fri Nov 19, 2021 4:47 pm
by charlie6

Hi,
giving my cent to continue this old forum thread
https://oldforum.puppylinux.com/viewtop ... t=measur3r

Using measur3r on various Pupplets never gave me the cm nor inch measured value.Only the pixel units one (see attached screenshot_1).
Each time, I needed using my pocket calculator, and a ruler, to convert from pixel to cm ... somewhat boring ... and time consuming ... :-/
So I dug in the measur3r script and found the hereafter given workaround. (See result in the attached screenshot_2)

script modification line 19: was

Code: Select all

read SCREEN_X SCREEN_Y  <<< `xwininfo -root | awk 'NR>=8&&NR<=9 {print $2}'`

new script line 19 is splitted in two lines:

Code: Select all

read SCREEN_X  <<< `xwininfo -root | awk 'NR>=8&&NR<=8 {print $2}'`
read SCREEN_Y  <<< `xwininfo -root | awk 'NR>=9&&NR<=9 {print $2}'`

Hope this helps, best regards from Belgium ;-D , Charlie


Re: measur3r

Posted: Fri Nov 19, 2021 7:45 pm
by JakeSFR

Yeah, this particular line stopped working at some point in some of my scripts. I updated most of them, but apparently missed this one.

It's because Bash used to treat a newline as a valid default delimiter for read, but it has changed in Bash 4+, IIRC.

Another way is to use a newline as a delimiter for read:

Code: Select all

read -d'\n' SCREEN_X SCREEN_Y  <<< `xwininfo -root | awk 'NR>=8&&NR<=9 {print $2}'`

or format it directly in awk to get rid of the newline completely:

Code: Select all

read SCREEN_X SCREEN_Y <<< `xwininfo -root | awk 'NR>=8&&NR<=9 {printf "%d ", $2}'`

Anyway, thanks for bringing my attention to it, I attached an updated PET.

Greetings!