bash script not working in conky [SOLVED]

Add functionality to your desktop
Forum rules
Before you post read how to get help. Topics in this forum are automatically closed 6 months after creation.
Post Reply
User avatar
Logansfury
Level 6
Level 6
Posts: 1237
Joined: Fri Oct 27, 2023 4:08 pm
Location: Las Vegas NV, USA

bash script not working in conky [SOLVED]

Post by Logansfury »

Good Morning everyone,

I am working on a display monitors info widget for my conky. The following 3 bash scripts work perfectly in terminal:

[code[
logansfury@OptiPlex-5040:~$ freq=$(xrandr | sed -n '/^HDMI-A-0/,/^[^[:space:]]/p' | awk 'sub("*"," "){print $2}'); echo "${freq:-No monitor detected}"
59.95
logansfury@OptiPlex-5040:~$ freq=$(xrandr | sed -n '/^HDMI-A-1/,/^[^[:space:]]/p' | awk 'sub("*"," "){print $2}'); echo "${freq:-No monitor detected}"
59.95
logansfury@OptiPlex-5040:~$ freq=$(xrandr | sed -n '/^DisplayPort-0/,/^[^[:space:]]/p' | awk 'sub("*"," "){print $2}'); echo "${freq:-No monitor detected}"
No monitor detected
logansfury@OptiPlex-5040:~$ [/code]

However, when I try to use in conky, it prevents the entire widget from displaying and I cannot get a start from terminal to keep a terminal open long enough to read anything:

Code: Select all

${color1}${goto 35}Display 1 Refesh Rate: ${alignr}${color0}${exec freq=$(xrandr | sed -n '/^HDMI-A-0/,/^[^[:space:]]/p' | awk 'sub("*"," "){print $2}'); echo "${freq:-No monitor detected}"}
can anyone edit and correct the above script for conky please?
Last edited by Logansfury on Wed Mar 20, 2024 3:01 pm, edited 1 time in total.
Image <-- Cick for sudo inxi --usb -Fxxxnmprz output, updated hourly!
User avatar
Koentje
Level 7
Level 7
Posts: 1581
Joined: Tue Jan 04, 2022 6:23 pm
Location: Netherlands

Re: bash script not working in conky

Post by Koentje »

If these long one-liners don't work, and that is often the case in conky, then put it in a bash script and call that bash script! This way it is more flexible..
Image
User avatar
Logansfury
Level 6
Level 6
Posts: 1237
Joined: Fri Oct 27, 2023 4:08 pm
Location: Las Vegas NV, USA

Re: bash script not working in conky

Post by Logansfury »

Koentje wrote: Wed Mar 20, 2024 1:20 pm If these long one-liners don't work, and that is often the case in conky, then put it in a bash script and call that bash script! This way it is more flexible..
I see what you mean. I believe I can use existing code you have provided for other scripts as a template to do this.
Image <-- Cick for sudo inxi --usb -Fxxxnmprz output, updated hourly!
User avatar
Koentje
Level 7
Level 7
Posts: 1581
Joined: Tue Jan 04, 2022 6:23 pm
Location: Netherlands

Re: bash script not working in conky

Post by Koentje »

You can try this:

Code: Select all

#!/bin/bash

while read -r ports
do

   freq=$(xrandr | sed -n "/^$ports/,/^[^[:space:]]/p" | awk 'sub("*"," "){print $2}') #'
   reso=$(xrandr | sed -n "/^$ports/,/^[^[:space:]]/p" | awk 'sub("*"," "){print $1}') #'

   echo -e "$ports\t$reso  $freq"

done < <(xrandr | grep -w 'connected' | awk '{print $1}')
It checks which ports are connected and then show the resolution and refreshrate of that port.
Still under construction because it has a small flaw... but should work on your system.
Image
User avatar
Logansfury
Level 6
Level 6
Posts: 1237
Joined: Fri Oct 27, 2023 4:08 pm
Location: Las Vegas NV, USA

Re: bash script not working in conky

Post by Logansfury »

Koentje wrote: Wed Mar 20, 2024 2:06 pm You can try this:

Code: Select all

#!/bin/bash

while read -r ports
do

   freq=$(xrandr | sed -n "/^$ports/,/^[^[:space:]]/p" | awk 'sub("*"," "){print $2}') #'
   reso=$(xrandr | sed -n "/^$ports/,/^[^[:space:]]/p" | awk 'sub("*"," "){print $1}') #'

   echo -e "$ports\t$reso  $freq"

done < <(xrandr | grep -w 'connected' | awk '{print $1}')
It checks which ports are connected and then show the resolution and refreshrate of that port.
Still under construction because it has a small flaw... but should work on your system.
I actually already did the execpi calls for 3 separate .sh scripts that query each individual display port. It's working perfectly :)
Image <-- Cick for sudo inxi --usb -Fxxxnmprz output, updated hourly!
Post Reply

Return to “Compiz, Conky, Docks & Widgets”