Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #!/bin/bash
- # Search these processes for the session variable
- # (they are run as the current user and have the DBUS session variable set)
- compatiblePrograms=( nemo pulseaudio trackerd nautilus )
- # Attempt to get a program pid
- for index in ${compatiblePrograms[@]}; do
- PID=$(pidof -s ${index})
- if [[ "${PID}" != "" ]]; then
- break
- fi
- done
- if [[ "${PID}" == "" ]]; then
- echo "Could not detect active login session"
- fi
- QUERY_ENVIRON="$(tr '\0' '\n' < /proc/${PID}/environ | grep "DBUS_SESSION_BUS_ADDRESS" | cut -d "=" -f 2-)"
- if [[ "${QUERY_ENVIRON}" != "" ]]; then
- export DBUS_SESSION_BUS_ADDRESS="${QUERY_ENVIRON}"
- # echo "Connected to session:"
- # echo "DBUS_SESSION_BUS_ADDRESS=${DBUS_SESSION_BUS_ADDRESS}"
- # Script to randomly set Background from files in a directory
- # Directory Containing Pictures is given via command-line, could be hardcoded in there as well
- DIR=$1
- #DIR="/home/user/Picture"
- #DIR="/home/user/Documents/cultural-festivities/"
- # Command to Select a random jpg file from directory
- PIC=$(find $DIR -type f -exec file {} \; | grep -o -P '^.+: \w+ image' | cut -d ':' -f 1 | shuf -n1)
- # Command to set Background Image
- gsettings set org.cinnamon.desktop.background picture-uri "file:///$PIC"
- else
- echo "Could not find dbus session ID in user environment."
- fi
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement