Skip to content

Instantly share code, notes, and snippets.

@kokoye2007
Last active January 12, 2020 10:16
Show Gist options
  • Save kokoye2007/32cb2d65e8a3052bbfde2b5262e3c581 to your computer and use it in GitHub Desktop.
Save kokoye2007/32cb2d65e8a3052bbfde2b5262e3c581 to your computer and use it in GitHub Desktop.
Wallpaper Changer Resource

Wallpaper Changer - Script

bash

  • Wallpaper Change in Command
gsettings set org.gnome.desktop.background picture-uri
  • Random Change
targetDir="/home/username/Photos"


function get_next_photo() {
    # Returns a random file form targetdir
    files=( "$targetDir"/* )
    echo "${files[RANDOM % ${#files[@]}]}"
}

function set_background() {
    # Takes an absolute file path as argument. Need * for spaces in path
    bg="$*"
    echo "Setting background to $bg"
    gsettings set org.gnome.desktop.background picture-uri "file://$bg"
}


background=$(get_next_photo)
echo "Next background is $background"
set_background $background

ref - askubuntu

Image

  • Unsplash
https://source.unsplash.com/1200x628/?penguin

URL - RES - KEYWORD

Current Resolution

  • xdyinfo
xdpyinfo | grep dimensions | sed -r 's/^[^0-9]*([0-9]+x[0-9]+).*$/\1/'
  • xrandr
xrandr --current | grep '*' | uniq | awk '{print $1}' 

Time

  • sleep
sleep (3)            - sleep for a specified number of seconds
sleep (1)            - delay for a specified amount of time
  • wait
fork (3am)           - basic process management
wait (2)             - wait for process to change state
  • watch
watch (1)            - execute a program periodically, showing output fullscreen
  • cornjob
schedule expressions
https://crontab.guru/#*/1_*_*_*_*

Case

case EXPRESSION in

  PATTERN_1)
    STATEMENTS
    ;;

  PATTERN_2)
    STATEMENTS
    ;;

  PATTERN_N)
    STATEMENTS
    ;;

  *)
    STATEMENTS
    ;;
esac

getopts

all=false
long=false

while getopts ":hal" option; do
  case $option in
    h) echo "usage: $0 [-h] [-a] [-l] file ..."; exit ;;
    a) all=true ;;
    l) long=true ;;
    ?) echo "error: option -$OPTARG is not implemented"; exit ;;
  esac
done

# remove the options from the positional parameters
shift $(( OPTIND - 1 ))

ls_opts=()
$all && ls_opts+=( -a )
$long && ls_opts+=( -l )

# now, do it
ls "${ls_opts[@]}" "$@"

ref https://unix.stackexchange.com/questions/20975/how-do-i-handle-switches-in-a-shell-script

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment