You are not logged in.
Hi I would like to ask
W=1920
H=1080
Display=$(xrandr | grep " connected " | awk '{ print$1 }')
xrandr --newmode "$Wx$H_60.00" 712.75 3840 4160 4576 5312 2160 2163 2168 2237 -hsync +vsync
xrandr --addmode $Display $Wx$H_60.00
xrandr --output $Display --mode $Wx$H_60.00
Wishing to get output from command in to variable:
cvt $W $H
How to grep this part for each new mode, when I'll change variables $W and $H?
712.75 3840 4160 4576 5312 2160 2163 2168 2237 -hsync +vsync
Offline
xrandr.get ()
{
declare -a Res=($(/usr/sbin/xrandr |grep " connected"));
echo ${Res[0]};
echo ${Res[2]%%+*}
}
I assume you use bash? Well, this may not include the final step, but I think you get the idea? By using array and parameter expansion to avoid external commands like awk.
Maybe this one even better?
$ declare -a Res=($(/usr/sbin/xrandr --listactivemonitors));
Last edited by solskog (2020-10-11 11:49:03)
Offline
@solskog not understood how I should use your function. Let me show my purposes.
In my dots I have .xinitrc where there wrote if cycle:
# set screen resolution
if [ -f /bin/xrandr ] ; then
Display=$(xrandr | grep " connected " | awk '{ print$1 }')
#4K
xrandr --newmode "3840x2160_60.00" 712.75 3840 4160 4576 5312 2160 2163 2168 2237 -hsync +vsync
xrandr --addmode $Display 3840x2160_60.00
xrandr --output $Display --mode 3840x2160_60.00
#FHD
#xrandr --newmode "1920x1080_60.00" 173.00 1920 2048 2248 2576 1080 1088 1120 -hsync +vsync
#xrandr --addmode $Display 1920x1080_60.00
#xrandr --output $Display --mode 1920x1080_60.00
fi
It's working perfect for my 4K monitor. But if some one else put my dots to his machine, it can totally not working, becouse that's data from my monitor:
712.75 3840 4160 4576 5312 2160 2163 2168 2237 -hsync +vsync
And other monitor can have some like this:
703.80 3840 4159 4565 5312 2140 2155 2168 2233 -hsync +vsync
See differences?
The one of way to resolve, this is enter your resolution by hand to variables, and "grep" other data to variables.
If you know some else, better then I have please write the code.
PS: After fresh install of Arch I have had maximal resolution only 1920x1200. If possible to do a maximal resolution by one string, I will be happy.
Offline
xrandr.get ()
{
declare -a FourK=($(cvt 3840 2160 60.0|tail -n 1));
declare -a Fhd=($(cvt 1920 1080 60.0|tail -n 1));
echo ${FourK[@]/Modeline/xrandr --newmode};
echo ${Fhd[@]/Modeline/xrandr --newmode}
}
Maybe I misunderstand again? You alreay known the resolution but looking for modeline data?
Last edited by solskog (2020-10-11 13:08:54)
Offline
xrandr.get () { declare -a FourK=($(cvt 3840 2160 60.0|tail -n 1)); declare -a Fhd=($(cvt 1920 1080 60.0|tail -n 1)); echo ${FourK[@]/Modeline/xrandr --newmode}; echo ${Fhd[@]/Modeline/xrandr --newmode} }
Maybe I misunderstand again? You alreay known the resolution but looking for modeline data?
I no need echo to screen. It's should apply for system. I remade the screen if and it unfotunally not working property:
if [ -f /bin/xrandr ] ; then
Display=$(xrandr | grep " connected " | awk '{ print$1 }')
declare -a Res=($(cvt 3840 2160 60.0|tail -n 1))
${Res[@]/Modeline/xrandr --newmode}
xrandr --addmode $Display 3840x2160_60.00
xrandr --output $Display --mode 3840x2160_60.00
fi
Last edited by Windslab (2020-10-11 13:23:30)
Offline
declare -a Res=($(cvt 3840 2160 60.0|tail -n 1))
${Res[@]/Modeline/xrandr --newmode}
The code is correct, what is not working?
Offline
The code is correct, what is not working?
xrandr: cannot find mode "3840x2160_60"
Offline
That's also not working and this is not good:
if [ -f /bin/xrandr ] ; then
Display=$(xrandr | grep " connected " | awk '{ print$1 }')
Mode=$(cvt 3840 2160 60.0)
xrandr --newmode "3840x2160_60.00" $($Mode | awk '{ print$15,$16,$17,$18,$19,$20,$21,$22,$23,$24,$25}')
xrandr --addmode $Display 3840x2160_60.00
xrandr --output $Display --mode 3840x2160_60.00
fi
Offline
This is on multiple levels wrong.
1. Unconditionally adding random modelines to outputs is no good idea at all and will often fail (because the HW chain doesn't support the mode)
2. There can be more than 1 output connected, so you cannot just grep a line, because there can be multiple lines as result
2a. piping grep to awk is a mortal sin: http://porkmail.org/era/unix/award.html
3. The command substitution doesn't substitute a command
4. You wanted a variable expansion in the first place (and no awk)
5. If you wanted to permanently/unconditionally add a modeline for your local system, you clearly also missed the respective section in the xrandr wiki page.
I suggest you start here: https://tldp.org/LDP/Bash-Beginners-Guide/html/ before you even remotely consider distributing anything.
You cannot just ask-and-error the forum to some hyper-fragile script that's gonna fall apart on the next corner and then advertise that (what you're going to do, judging from your forum history) - this will expectably lead to a disaster.
Of course that doesn't work.
Stop abusing the forum to ask-end-error yourself to some broken installer script.
Online
This is on multiple levels wrong.
1. Unconditionally adding random modelines to outputs is no good idea at all and will often fail (because the HW chain doesn't support the mode)
2. There can be more than 1 output connected, so you cannot just grep a line, because there can be multiple lines as result
2a. piping grep to awk is a mortal sin: http://porkmail.org/era/unix/award.html
3. The command substitution doesn't substitute a command
4. You wanted a variable expansion in the first place (and no awk)
5. If you wanted to permanently/unconditionally add a modeline for your local system, you clearly also missed the respective section in the xrandr wiki page.I suggest you start here: https://tldp.org/LDP/Bash-Beginners-Guide/html/ before you even remotely consider distributing anything.
You cannot just ask-and-error the forum to some hyper-fragile script that's gonna fall apart on the next corner and then advertise that (what you're going to do, judging from your forum history) - this will expectably lead to a disaster.Of course that doesn't work.
Stop abusing the forum to ask-end-error yourself to some broken installer script.
I know linux from Slackware times. And I working in federal security segment.
I just like other people can't to know all in this life.
No. My installation scripts nice. This works perfect:
# set screen resolution
if [ -f /bin/xrandr ] ; then
Display=$(xrandr | grep " connected " | awk '{ print$1 }')
xrandr --newmode "3840x2160_60.00" 712.75 3840 4160 4576 5312 2160 2163 2168 2237 -hsync +vsync
xrandr --addmode $Display 3840x2160_60.00
xrandr --output $Display --mode 3840x2160_60.00
fi
An this one works good:
$($Mode | awk '{ print$15,$16,$17,$18,$19,$20,$21,$22,$23,$24,$25}')
Shows:
712.75 3840 4160 4576 5312 2160 2163 2168 2237 -hsync +vsync
Maybe something problems with string colaboration. I'll check.
Offline