You are not logged in.

#1 2016-08-24 01:17:23

BeerGeekGamer
Member
From: Normal, IL
Registered: 2016-04-10
Posts: 18

[SOLVED] How do you have i3 config, execute a custom script

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

#2 2016-08-24 02:56:53

ewaller
Administrator
From: Pasadena, CA
Registered: 2009-07-13
Posts: 19,768

Re: [SOLVED] How do you have i3 config, execute a custom script

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

#3 2016-08-24 14:45:58

BeerGeekGamer
Member
From: Normal, IL
Registered: 2016-04-10
Posts: 18

Re: [SOLVED] How do you have i3 config, execute a custom script

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

#4 2016-08-24 16:32:00

jasonwryan
Anarchist
From: .nz
Registered: 2009-05-09
Posts: 30,424
Website

Re: [SOLVED] How do you have i3 config, execute a custom script

`[` is a command: it requires spaces around it.


Arch + dwm   •   Mercurial repos  •   Surfraw

Registered Linux User #482438

Offline

#5 2016-08-24 19:39:52

PhilippD
Member
Registered: 2015-02-06
Posts: 40

Re: [SOLVED] How do you have i3 config, execute a custom script

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

#6 2016-08-24 20:37:07

null
Member
Registered: 2009-05-06
Posts: 398

Re: [SOLVED] How do you have i3 config, execute a custom script

PhilippD wrote:

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

#7 2016-08-26 12:34:22

BeerGeekGamer
Member
From: Normal, IL
Registered: 2016-04-10
Posts: 18

Re: [SOLVED] How do you have i3 config, execute a custom script

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

Board footer

Powered by FluxBB