Skip to content

Instantly share code, notes, and snippets.

@brianredbeard
Created September 26, 2018 05:19
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save brianredbeard/426b9f24e67af37838ccbdcfdc736e22 to your computer and use it in GitHub Desktop.
Save brianredbeard/426b9f24e67af37838ccbdcfdc736e22 to your computer and use it in GitHub Desktop.
Call external script from udev rule - I use this mechanism to fire off xrandr rules when docking my laptop.
#!/bin/sh
# This script will make two connected output sources mirrors of each other:
#
#
# +---------------+ +---------------+
# | | | |
# | Primary | | DisplayLink |
# | Display | | (DP-2-2) |
# | (e-DPI-1) | | (Screen 2/3) |
# | (Screen 1) | | |
# | | | |
# +---------------+ +---------------+
# ^ +---------------->
# | | +---------------+
# | | | |
# | | | VGA |
# | | | (DP-2-3) |
# +--------------+ | (Screen 2/3) |
# | LAPTOP | | |
# +--------------+ | |
# +---------------+
LOGFILE="/tmp/docklog-$(date +%s)"
if [[ "$ACTION" == "add" ]]; then
DOCKED=1
logger -t DOCKING "Detected condition: docked"
elif [[ "$ACTION" == "remove" ]]; then
DOCKED=0
logger -t DOCKING "Detected condition: un-docked"
else
logger -t DOCKING "Detected condition: unknown"
echo Please set env var \$ACTION to 'add' or 'remove'
exit 1
fi
export DISPLAY=:0
username="bharrington"
sleep 0.5
su ${username} -c '
/usr/bin/xrandr --output DP-2-2 --right-of eDP-1;
/usr/bin/xrandr --output DP-2-3 --same-as DP-2-2 --right-of eDP-1;
notify-send -t 5000 "ext_mirror.sh executed" ;
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment