measur3r script modified to give inch/cm units

Moderator: Forum moderators

Post Reply
User avatar
charlie6
Posts: 44
Joined: Wed Sep 09, 2020 12:59 pm
Location: Namur, Belgium
Has thanked: 5 times
Been thanked: 6 times

measur3r script modified to give inch/cm units

Post 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

Attachments
modified script
modified script
measur3r_2.png (8.1 KiB) Viewed 1644 times
existing script
existing script
measur3r_1.png (7.47 KiB) Viewed 1644 times
Last edited by Flash on Fri Nov 19, 2021 9:00 pm, edited 1 time in total.
Reason: Originat title: measur3r
User avatar
JakeSFR
Posts: 277
Joined: Wed Jul 15, 2020 2:23 pm
Been thanked: 159 times

Re: measur3r

Post 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!

Attachments
measur3r-1.4.pet
MD5: 597b75a0f3af5633c43e56515defb331 measur3r-1.4.pet
(2.38 KiB) Downloaded 57 times
[O]bdurate [R]ules [D]estroy [E]nthusiastic [R]ebels => [C]reative [H]umans [A]lways [O]pen [S]ource
Omnia mea mecum porto.
Post Reply

Return to “Engineering/Science/Simulation”