Last active
November 27, 2022 15:12
-
-
Save isaaclw/84ff57049401f11a38cbf3fb26f008cc to your computer and use it in GitHub Desktop.
Load display
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# http://stackoverflow.com/a/1162345/971529 | |
load_display() { | |
if [ -z "$1" ]; then | |
PID=$(pgrep -n -u $USER 'gnome-session|xfdesktop|xterm|kodi|lxsession|mate-session') | |
else | |
PID=$(pgrep -n -u $USER -f "$1") | |
fi | |
FALLBACK=$(pgrep -n 'unity-greeter') | |
if [ -n "$PID" ]; then | |
export DISPLAY=$(cat /proc/$PID/environ | strings | awk 'BEGIN{FS="=";} $1=="DISPLAY" {print $2; exit}') | |
echo "DISPLAY set to $DISPLAY" | |
elif [ -n "$FALLBACK" ]; then | |
export DISPLAY=$(sudo cat /proc/$FALLBACK/environ | strings | awk 'BEGIN{FS="=";} $1=="DISPLAY" {print $2; exit}') | |
echo "Using Login Screen. DISPLAY set to $DISPLAY" | |
else | |
echo "Could not set DISPLAY" | |
fi | |
unset PID | |
} | |
# needs to be a function since it loads it into the current environment |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment