Skip to content

Instantly share code, notes, and snippets.

@yihyang
Created July 25, 2018 04:15
Show Gist options
  • Select an option

  • Save yihyang/bc132111c17ba5b438e2225e39fc5d1f to your computer and use it in GitHub Desktop.

Select an option

Save yihyang/bc132111c17ba5b438e2225e39fc5d1f to your computer and use it in GitHub Desktop.
Make fun of your friend by changing their wallpaper fast using this program. Start by putting all the wallpapers inside "wallpapers" folder on Desktop.
cd ~/Desktop/wallpapers
# find the available files
photos=`find ${PWD} -type f -maxdepth 2 -name "*.jpg" -o -name "*.png"`
# Select Random photos
numlines="$(printf "%s\n" "${photos}" | wc -l)"
lineno="$((${RANDOM} % ${numlines} + 1))"
random_line="$(printf "%s\n" "${photos}" | sed -n "${lineno}{p;q;}")"
echo $random_line
osascript -e "tell application \"Finder\" to set desktop picture to POSIX file \"${random_line}\""
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment