Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #!/bin/bash
- #####################################################
- ## use this script with crontab and some global keyboard shortcut
- ## commands to `sed` its 18th line (by some script)
- ## and enjoy your best wallpapers
- ## BY MOSAID
- #####################################################
- #### directories ####
- #####################################################
- D0="/media/mosaid/My_Data/Images" # alt H
- D1="$D0/collectionWallpapers" # alt G
- D2="$D0/001 images/wallhaven/myBackgrunds" # alt F
- D3="$D0/001 images/wallhaven/bg0s"
- D4="/home/mosaid/Pictures/wallhaven/myBackgrunds"
- D5=""
- D6=""
- #####################################################
- DIR=$D0 ### changed by global keyboard shortcuts
- #####################################################
- DIRECTORY="/media/mosaid/WindowsDir/Users/mosaid/GoogleDrive/linux/scripts0/wallp"
- PREV="$DIRECTORY/.prev"
- IMAGES="$DIRECTORY/.wlist"
- FAV="$DIRECTORY/.fav"
- NOTES="$DIRECTORY/.notes"
- LAST="$DIRECTORY/.last"
- #####################################################
- function printhelp () {
- string1=$1
- string2=$2
- pad=$( printf '%0.1s' " "{1..60} )
- padlength=25
- printf '\t%s' "$string1"
- printf '%*.*s' 0 $(( padlength - ${#string1} )) "$pad"
- printf '%s\n' "$string2"
- }
- function selectPIC () {
- PIC=$( find "$DIR/" -type f -printf "%p\n" | shuf -n1 )
- if grep -w "$PIC" "$PREV" >/dev/null
- then return 0 # $PIC is found in history
- fi
- tmp=$(dirname "$PIC" )
- if grep -w "$tmp" "$IMAGES" >/dev/null
- then return 1 # $DIR is listed in $IMAGES
- else return 0 # $DIR not listed in $IMAGES
- fi
- }
- #####################################################
- #### handle the args ####
- #####################################################
- case "$1" in
- "a" | "-a" | "--appearance" ) # mate appearance properties
- mate-appearance-properties >/dev/null 2>&1 &
- ;;
- "p" | "-p" | "--previous" ) #previous wallpaper
- if [ "$DIR" == "" ] ; then
- SF=$( cat "$FAV" | wc -l )
- LF=$( cat "$LAST" )
- let " LF = LF - 1 "
- if (( $LF <= 1 )) ; then LF=$SF ; fi
- PIC=$( sed -n "$LF"p "$FAV" )
- echo "$LF" > "$LAST"
- else
- PIC=$(cat $PREV | tail -2 |sed -n "1p" )
- fi
- sed -i '$ d' $PREV
- truncate -s -1 $PREV
- ;;
- "c" | "-c" | "--current" ) #print path to current wallpaper
- PIC=$(cat $PREV | tail -1 )
- echo "$PIC"
- ;;
- "o" | "-o" | "--open" ) #open current wallpaper
- PIC=$(cat $PREV | tail -1 )
- gnome-open "$PIC"
- ;;
- "f" | "-f" | "--fav" ) # add current wallpaper to favourites
- PIC=$(cat $PREV | tail -1 )
- L=$( cat "$FAV" | grep -n "$PIC" | cut -f1 -d: | head -n 1 )
- re='^[0-9]+$'
- if ! [[ $L =~ $re ]] ; then echo "$PIC" >> $FAV ; else echo "already a favourite" ; fi
- ;;
- "r" | "-r" | "--remove" ) #remove current wallpaper from favourites"
- PIC=$(cat $PREV | tail -1 )
- L=$( cat "$FAV" | grep -n "$PIC" | cut -f1 -d: | head -n 1 )
- re='^[0-9]+$'
- if [[ $L =~ $re ]] ; then sed -i "$L"d "$FAV" ; else echo "not a favourite" ; fi
- ;;
- "n" ) #save a note about current wallpaper
- if [ -z "$2" ] ; then
- echo "usage : `basename $0` < n > < note > "
- else
- PIC=$(cat $PREV | tail -1 )
- echo "" >>"$NOTES"
- echo "$2" >>"$NOTES"
- echo "$PIC" >>"$NOTES"
- fi
- ;;
- "nn" | "notes" | "--notes" )
- cat "$NOTES"
- ;;
- "-h" | "h" | "help" | "--help" )
- printhelp "h, -h, --help" "print this help"
- printhelp "" "next wallpaper"
- printhelp "a, -a, --appearance" "mate appearance"
- printhelp "p, -p, --previous" "previous wallpaper"
- printhelp "c, -c, --current" "print path to current wallpaper"
- printhelp "o, -o, --open" "gnome open current wallpaper"
- printhelp "f, -f, --fav" "add current wallpaper to favourites"
- printhelp "r, -r, --remove" "remove current wallpaper from favourites"
- printhelp "n [note]" "save a note about current wallpaper"
- printhelp "nn, notes, --notes" "print saved notes"
- ;;
- "" ) # no aguments , next wallpaper
- if [ "$DIR" == "" ]
- then #select pic from favourites
- LF=$( cat "$LAST" )
- SF=$( cat "$FAV" | wc -l )
- let " LF += 1"
- if (( $LF > $SF )) ; then LF=1 ; fi
- echo "$LF" > "$LAST"
- PIC=$( sed -n "$LF"p "$FAV" )
- else #select random pic from $DIR preferably not previously used and $DIR is listed in $IMAGES
- result=0
- count=0
- while [ $result == 0 ] && (( $count < 20 )) ; do
- selectPIC
- result=$?
- let " count += 1 "
- done
- fi
- printf "\n$PIC" >> $PREV # save pic in history
- ;;
- * ) # default
- echo "command not recognized use --help"
- ;;
- esac
- #####################################################
- PID=$(pgrep mate-session)
- export DBUS_SESSION_BUS_ADDRESS=$(grep -z DBUS_SESSION_BUS_ADDRESS /proc/$PID/environ|cut -d= -f2-)
- #####################################################
- ### go ahead if $PIC is a valid image file ###
- #####################################################
- if `file "$PIC" | grep -w image >/dev/null` ; then
- gsettings set org.mate.background picture-filename "$PIC"
- dim=$( identify -format '%w %h' "$PIC" )
- dim=( $dim )
- if (( ${dim[0]} <= 1920 )) && (( ${dim[1]} <= 1080 ))
- then option='stretched'
- else option='scaled'
- fi
- gsettings set org.mate.background picture-options "$option"
- fi
- #####################################################
- #### truncate history ####
- #####################################################
- SIZE=100
- length=$(cat $PREV | wc -l)
- if (( $length > $SIZE )) ; then
- let " length = length - $SIZE "
- sed -i "1,$length"d $PREV
- fi
- ################## THE END ########################
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement