Skip to content

Instantly share code, notes, and snippets.

@doublecompile
Last active April 11, 2017 14:21
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save doublecompile/c2925a4a570c991af60d to your computer and use it in GitHub Desktop.
Save doublecompile/c2925a4a570c991af60d to your computer and use it in GitHub Desktop.
Rotates a wallpaper on either Gnome or OS X
#!/bin/bash
# Rotate wallpapers on GNOME or OSX
# (OSX users need to install coreutils)
set -e
WALLPAPERS="$HOME/wallpaper"
if [[ -n "$(command -v gsettings)" ]]; then
paper=`find $WALLPAPERS -type f | shuf -n 1`
PID=$(pgrep gnome-session)
export DBUS_SESSION_BUS_ADDRESS=$(grep -z DBUS_SESSION_BUS_ADDRESS /proc/$PID/environ|cut -d= -f2-)
gsettings set org.gnome.desktop.background picture-uri "file:///$paper"
elif [[ -n "$(command -v osascript)" ]]; then
paper=`find $WALLPAPERS -type f | gshuf -n 1`
osascript -e "tell application \"Finder\" to set desktop picture to POSIX file \"$paper\""
fi
@doublecompile
Copy link
Author

I also have a cron entry:

0 *     * * *      /home/doublecompile/bin/rotate-wallpaper

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