Posted by ANGE on Mon 11th Jan 18:59 (modification of post by corenominal view diff)
diff | download | new post
- #!/bin/bash
- # Author:
- # Philip Newborough <corenominal@corenominal.org>
- # Copyright:
- # © 2008 Philip Newborough <corenominal@corenominal.org>
- # License:
- # This program is free software; you can redistribute it and/or
- # modify it under the terms of the GNU Lesser General Public
- # License as published by the Free Software Foundation; either
- # version 2.1 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
- # Lesser General Public License for more details.
- #
- # You should have received a copy of the GNU Lesser General Public
- # License along with this library; if not, write to the Free Software
- # Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
- #
- # On Debian systems, the complete text of the GNU Lesser General Public
- # License V2.1 can be found in the file `/usr/share/common-licenses/LGPL-2.1'.
- #-------------------------------------------------------------------------------
- # Display help
- if [ "$1" = "" ] || [ "$1" = "-h" ] || [ "$1" = "--help" ]; then
- echo "Usage:"
- echo " rotate-wallpaper --path DIRECTORY"
- echo ""
- echo " -h, --help"
- echo " Shows this message and exits."
- echo " -p, --path"
- echo " Set path to directory containing images."
- echo ""
- exit
- fi
- if [ "$1" = "-p" ] || [ "$1" = "--path" ];then
- if [ ! "$2" = "" ];then
- # Set the path to your wallpaper directory
- WALLPAPERS=$2
- # Sanity check. Does wallpaper directory exist
- if [ ! -d $WALLPAPERS ]; then
- echo "Oops! Specified directory does not exist."
- echo ""
- rotate-wallpaper --help
- exit 1
- fi
- # Sanity check. Is wallpapers directory completely empty of files?
- if [ ! "$(ls -A $WALLPAPERS)" ]; then
- echo "Oops! No images found within specified directory."
- echo ""
- rotate-wallpaper --help
- exit 1
- fi
- # Sanity check. Is wallpapers directory empty of images?
- # + Build query
- QUERY=""
- if [ "$(ls $WALLPAPERS/*.jpg 2> /dev/null)" ]; then
- QUERY="$QUERY$WALLPAPERS/*.jpg "
- fi
- if [ "$(ls $WALLPAPERS/*.JPG 2> /dev/null)" ]; then
- QUERY="$QUERY$WALLPAPERS/*.JPG "
- fi
- if [ "$(ls -l $WALLPAPERS/*.PNG 2> /dev/null)" ]; then
- QUERY="$QUERY$WALLPAPERS/*.PNG "
- fi
- if [ "$(ls -l $WALLPAPERS/*.png 2> /dev/null)" ]; then
- QUERY="$QUERY$WALLPAPERS/*.png "
- fi
- if [ "$QUERY" = "" ];then
- echo "Oops! No images found within specified directory."
- echo ""
- rotate-wallpaper --help
- exit 1
- fi
- # Sanity check. Does config directory exist?
- if [ ! -d ~/.config/rotate-wallpaper ]; then
- mkdir ~/.config/rotate-wallpaper
- fi
- # Sanity check. Does config file exist?
- if [ ! -f ~/.config/rotate-wallpaper/count ]; then
- touch ~/.config/rotate-wallpaper/count
- echo "0" > ~/.config/rotate-wallpaper/count
- fi
- # Count number of wallpapers
- NO_OF_WALLPAPERS=0
- for file in $QUERY; do
- if [ ! -d "$file" ];then
- NO_OF_WALLPAPERS=$(( NO_OF_WALLPAPERS+1 ))
- fi
- done
- # Read in number of last wallpaper displayed, or start from 1
- PREVIOUS_WALLPAPER="$(cat ~/.config/rotate-wallpaper/count)"
- NEW_WALLPAPER=$(( PREVIOUS_WALLPAPER+1 ))
- # Do we need to loop back to 1?
- if [ $NEW_WALLPAPER -gt $NO_OF_WALLPAPERS ];then
- NEW_WALLPAPER=1
- fi
- # Set wallpaper
- CNT=1
- for file in $QUERY; do
- if [ $CNT = $NEW_WALLPAPER ]; then
- if [ ! -d "$file" ];then
- FILE_TYPE=$(file -i "$file")
- if [ "$FILE_TYPE" = "$file: image/png" ] || \
- [ "$FILE_TYPE" = "$file: image/jpeg" ];then
- nitrogen --set-scaled "$file"
- fi
- fi
- fi
- CNT=$(( CNT+1 ))
- done
- # Save count and exit
- echo "$NEW_WALLPAPER" > ~/.config/rotate-wallpaper/count
- exit
- else
- # Show error if no directory given
- echo "Oops! Image directory not specified."
- echo ""
- rotate-wallpaper --help
- exit 1
- fi
- fi
- # If all else fails
- echo "Oops! Invalid command. Have a clue..."
- rotate-wallpaper --help
- exit 1
Submit a correction or amendment below (click here to make a fresh posting)
After submitting an amendment, you'll be able to view the differences between the old and new posts easily.