Skip to content

Instantly share code, notes, and snippets.

@eliminmax
Forked from 3lpsy/x-resize
Last active December 28, 2022 05:21
Show Gist options
  • Save eliminmax/f2eff01a304607b4249cbc4f027cbd91 to your computer and use it in GitHub Desktop.
Save eliminmax/f2eff01a304607b4249cbc4f027cbd91 to your computer and use it in GitHub Desktop.
3lpsy/x-resize, modified for my Linux from Scratch VM
#!/bin/bash
# 3lpsy/x-resize, modified for my Linux From Scratch VM
## Ensure Log Directory Exists
LOG_DIR=/var/log/autores;
if [ ! -d $LOG_DIR ]; then
mkdir $LOG_DIR;
fi
LOG_FILE=${LOG_DIR}/autores.log
## Function to find User Sessions & Resize their display
function x_resize() {
declare -A disps usrs
usrs=()
disps=()
for i in $(users);do
[[ $i = root ]] && continue # skip root
usrs[$i]=1
done
for u in "${!usrs[@]}"; do
for i in $(sudo ps e -u "$u" | sed -rn 's/.* DISPLAY=(:[0-9]*).*/\1/p');do
disps[$i]=$u
done
done
for d in "${!disps[@]}";do
session_user="${disps[$d]}"
session_display="$d"
session_output=$(sudo -u "$session_user" PATH=/usr/bin DISPLAY="$session_display" xrandr | awk '/ connected/{print $1; exit; }')
echo "Session User: $session_user" | tee -a $LOG_FILE;
echo "Session Display: $session_display" | tee -a $LOG_FILE;
echo "Session Output: $session_output" | tee -a $LOG_FILE;
sudo -u "$session_user" PATH=/usr/bin DISPLAY="$session_display" xrandr --output "$session_output" --auto | tee -a $LOG_FILE;
done
}
echo "Resize Event: $(date)" | tee -a $LOG_FILE
x_resize
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment