Skip to content

Instantly share code, notes, and snippets.

@roelofr
Last active August 9, 2021 07:50
Show Gist options
  • Select an option

  • Save roelofr/f9ffba5a9beaac149c117d886a8c02b9 to your computer and use it in GitHub Desktop.

Select an option

Save roelofr/f9ffba5a9beaac149c117d886a8c02b9 to your computer and use it in GitHub Desktop.
A collection of useful scripts

Random Wallpapers

This is a script for Ubuntu that sets a random wallpaper whenever you invoke it, and works from cronjobs, so you can do cool stuff like cycle your wallpaper every 30 minutes:

Installation

Just download the random-wallpaper.sh and put it somewhere. I'd recommend $HOME/bin, but you can put it anywhere and then chmod u+x it.

Scheduling

You can use cron to schedule the wallpaper change with a certain interval.

For a new wallaper every 30 minutes, for example, do:

*/30 * * * * $HOME/bin/random-wallpaper.sh

Change image query

The API is simple, https://source.unsplash.com/<size>/?<query>. Just modify line 18 as you see fit.

#!/bin/bash
# Fail on errors
set -e
# Check temp
UNSPLASH_DIR="$HOME/.cache/unsplash"
test -d "$UNSPLASH_DIR" || mkdir "$UNSPLASH_DIR"
# Removing old bgs
echo "Removed files: "
find "$UNSPLASH_DIR" -type f -mtime 1 -print -delete
# Make temp file
TEMPFILE=$( tempfile --prefix 'random-' --suffix '.jpg' --directory "$UNSPLASH_DIR" )
# Get background
curl --location --fail --silent --output "$TEMPFILE" "https://source.unsplash.com/1920x1080/?nature,dark"
touch "$TEMPFILE"
echo "Wrote to ${TEMPFILE}"
# export DBUS_SESSION_BUS_ADDRESS environment variable
PID=$( pgrep gnome-session | head -n 1 )
export DBUS_SESSION_BUS_ADDRESS=$( grep -z DBUS_SESSION_BUS_ADDRESS /proc/$PID/environ | cut -d= -f2- )
# Change background
echo "Assigning background"
gsettings set org.gnome.desktop.background picture-uri "$TEMPFILE"
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment