(varname)
When himawaripy is called by cron or an init, the environment variables that
    are available to us is severely limited, causing problems with some
    processes we call (such as gsetings [due to lack of
    $DBUS_SESSION_BUS_ADDRESS for instance]).

    To try fix this issue as much as we can, without resorting to additional
    shell scripts, we try fetching values of the environment variables we are
    interested in (before we access them!) from another process. pulseauido
    seemed to me a good choice, for it's available virtually on all desktop
    installations (regardless of DE), and seem to have all the environment
    variables that we are (potentially) interested in (*e.g.* gdm does NOT have
    $DISPLAY whereas pulseaudio do!)
When himawaripy is called by cron or an init, the environment variables that
    are available to us is severely limited, causing problems with some
    processes we call (such as gsetings [due to lack of
    $DBUS_SESSION_BUS_ADDRESS for instance]).
When himawaripy is called by cron or an init the environment variables that are available to us is severely limited causing problems with some processes we call ( such as gsetings [ due to lack of $DBUS_SESSION_BUS_ADDRESS for instance ] ) .
def fetch_envvar(varname):
    """
    When himawaripy is called by cron or an init, the environment variables that
    are available to us is severely limited, causing problems with some
    processes we call (such as gsetings [due to lack of
    $DBUS_SESSION_BUS_ADDRESS for instance]).

    To try fix this issue as much as we can, without resorting to additional
    shell scripts, we try fetching values of the environment variables we are
    interested in (before we access them!) from another process. pulseauido
    seemed to me a good choice, for it's available virtually on all desktop
    installations (regardless of DE), and seem to have all the environment
    variables that we are (potentially) interested in (*e.g.* gdm does NOT have
    $DISPLAY whereas pulseaudio do!)
    """

    if varname in os.environ:
        return

    val = (
        os.popen('bash -c "grep -z ^{}= /proc/$(pgrep -n pulseaudio)/environ | cut -d= -f2-"'.format(varname))
        .read()
        .strip("\0\n")
    )
    if val:
        print("Fetched env. var. {} as `{}`".format(varname, val))
        os.environ[varname] = val
    else:
        print("Could NOT retrieve env. var. {}".format(varname))
def fetch_envvar ( varname ) : if varname in os . environ : return val = ( os . popen ( 'bash -c "grep -z ^{}= /proc/$(pgrep -n pulseaudio)/environ | cut -d= -f2-"' . format ( varname ) ) . read ( ) . strip ( "\0\n" ) ) if val : print ( "Fetched env. var. {} as `{}`" . format ( varname , val ) ) os . environ [ varname ] = val else : print ( "Could NOT retrieve env. var. {}" . format ( varname ) )