Last active
December 12, 2015 04:28
-
-
Save ianliu/4714307 to your computer and use it in GitHub Desktop.
This is a very simple script I did for changing the background in periods of time. The script was tested in Ubuntu 12.04.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/bin/bash | |
# | |
# Copyright 2013 Ian Liu Rodrigues <[email protected]> | |
# | |
# This program is free software: you can redistribute it and/or modify | |
# it under the terms of the GNU General Public License as published by | |
# the Free Software Foundation, either version 3 of the License, or | |
# (at your option) any later version. | |
# | |
# This program is distributed in the hope that it will be useful, | |
# but WITHOUT ANY WARRANTY; without even the implied warranty of | |
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | |
# GNU General Public License for more details. | |
# | |
# You should have received a copy of the GNU General Public License | |
# along with this program. If not, see <http://www.gnu.org/licenses/>. | |
# Rationale | |
# ========= | |
# This is a very simple script for changing the desktop background in periods | |
# of time. | |
# Installation | |
# ============ | |
# 1. Give execution permission to this script: | |
# chmod +x bgchanger.sh | |
# | |
# 2. Move it to a folder in your home: | |
# mkdir -p ~/.scripts && mv bgchanger.sh ~/.scripts | |
# | |
# 3. Create a startup application to run this script: | |
# https://help.ubuntu.com/community/AddingProgramToSessionStartup | |
# | |
# 4. Almost done! Now you need to configure the script, see below. | |
# Configuring | |
# =========== | |
# You can modify the following variables to suit better your needs: | |
# (default values are in brackets []) | |
# | |
# DIR [$HOME/Pictures/Wallpapers] | |
# The directory where the wallpapers are. | |
# | |
# | |
# PERIOD [20m] | |
# The interval of time in which wallpapers are going to change. | |
# This value is passed directly to the shell command sleep. See | |
# its man page for the time format. | |
LOCKFILE=/tmp/bgchanger-$HOSTNAME | |
if ! ln -s `basename $LOCKFILE` $LOCKFILE ; then exit ; fi | |
trap 'rm -f $LOCKFILE ; [[ $sleepid ]] && kill $sleepid ; exit' SIGTERM SIGHUP SIGINT SIGABRT SIGQUIT | |
DIR=$HOME/Pictures/Wallpapers | |
PERIOD=20m | |
# ============================================================================ | |
# Only change the lines below if you know what you are doing! :) | |
while true ; do | |
sleep $PERIOD & sleepid=$! | |
wait | |
FILES=(`ls -1 $DIR | grep -v ^_`) | |
MAXNUMBER=${#FILES[@]} | |
number=$(($RANDOM % $MAXNUMBER)) | |
file=file://$DIR/${FILES[$number]} | |
echo "Changing background to $file" | |
gsettings set org.gnome.desktop.background picture-uri "$file" | |
done |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment