You are not logged in.
Hello,
I'm trying to map my Fn+F5 key to run a script I created for controlling the display toggle. From using xev, I found out that they keycode for that combination is 133, so I have the following in my i3/config file
bindcode 133 exec /home/beergeekgamer/scripts/monitors/display_toggle.sh
The following is the code from my display_toggle.sh
#!/bin/bash
laptop=eDP1
vga=DP1
hdmi=HDMI1
if xrandr | grep "$vga disconnected"; then
xrandr --output "$vga" --off --output "$laptop" --auto
else
xrandr --output "$vga" --auto
fi
If I run it from the terminal
bash scripts/monitors/display_toggle.sh
it runs fine, but when I try Fn+F5 nothing happens. I mapped the Fn+F5 to a different script and it ran fine, so I know its not the keycode, so the issue seems to be my script, but like I said it runs fine manually from the terminal. Doe anyone have any ideas. Thanks in advanced.
Last edited by BeerGeekGamer (2016-08-26 12:34:43)
Offline
First, ensure that your script has the executable bit set.
Then, use xev to find out what the key is called in X, then bind it like this:
bindsym XF86AudioPlay exec scripts/monitors/display_toggle.sh
Change the XF86AudioPlay to what xev tells you.
Remember to reload the configuration if yo are in i3.
Nothing is too wonderful to be true, if it be consistent with the laws of nature -- Michael Faraday
Sometimes it is the people no one can imagine anything of who do the things no one can imagine. -- Alan Turing
---
How to Ask Questions the Smart Way
Offline
I figured out the issue, it had to deal with correct permissions. Once I ran
chmod u+x scripts/monitors/display_toggle.sh
the following script ran fine:
#!/bin/bash
laptop=eDP1
vga=DP1
hdmi=HDMI1
virtual=VIRTUAL1
if xrandr | grep "$vga disconnected"; then
xrandr --output "$vga" --off --output "$laptop" --auto
else
xrandr --output "$laptop" --primary --mode 1920x1080 --pos 0x0 --rotate normal --output "$vga" --mode 1920x1080 --pos 1920x0 --rotate normal
fi
The issue now is, I would really like to have the script be the following:
if [xrandr | grep "$vga connected"]; then
xrandr --output "$hdmi" --off --output "$vga" --mode 1920x1080 --pos 1920x0 --rotate normal --output "$laptop" --primary --mode 1920x1080 --pos 0x0 --rotate normal --output "$virtual" --off
else
xrandr --output "$hdmi" --off --output "$vga" --off --output "$laptop" --primary --mode 1920x1080 --pos 0x0 --rotate normal --output "$virtual" --off
fi
but for whatever reason the script doesn't seem to run and the only thing I can think of is it doesn't recognize the "$vga connected". Any ideas? If I need to make a separate thread, just let me know.
Offline
`[` is a command: it requires spaces around it.
Offline
Try
if [[ $(xrandr | grep "$vga connected") != "" ]]
Or simply run it from the terminal and read the error messages.
Last edited by PhilippD (2016-08-24 19:40:34)
Offline
Try
if [[ $(xrandr | grep "$vga connected") != "" ]]
if xrandr | grep -q "$vga connected"; then ...
Why use unnecessary comparisons?
Last edited by null (2016-08-24 20:39:51)
Offline
Thanks for finding my typo. I'm going to mark this as solved even though I think I'm going to go a different route, which is using udev.
Offline