Created
June 21, 2017 20:19
-
-
Save swiesend/da0ac40de13f73cec0aefa65eaf0056d to your computer and use it in GitHub Desktop.
get DBUS_SESSION_BUS_ADDRESS and DISPLAY for cronjobs with gui tasks
This file contains 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
#!/bin/sh | |
[ "$#" -lt 1 ] && echo "Usage: $0 program options" && exit 1 | |
program="$1" | |
shift | |
user=$(whoami) | |
env_reference_process=$( pgrep -u "$user" xfce4-session || pgrep -u "$user" ciannamon-session || pgrep -u "$user" gnome-session || pgrep -u "$user" gnome-shell || pgrep -u "$user" kdeinit ) | |
export DBUS_SESSION_BUS_ADDRESS=$(cat /proc/"$env_reference_process"/environ | grep -z ^DBUS_SESSION_BUS_ADDRESS= | sed 's/DBUS_SESSION_BUS_ADDRESS=//') | |
export DISPLAY=$(cat /proc/"$env_reference_process"/environ | grep -z ^DISPLAY= | sed 's/DISPLAY=//') | |
"$program" "$@" |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment