SHARE
TWEET

mkwlppr

charles95 Apr 19th, 2015 (edited) 931 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. #!/bin/sh
  2. #This script creates XML files that can act as dynamic wallpapers for GNOME by referring to multiple wallpapers
  3. #Coded by David J Krajnik
  4.  
  5. if [ "$*" = "" ]; then
  6.   echo "This script creates XML files that can act as dynamic backgrounds for GNOME by referring to multiple wallpapers"
  7.   echo "Usage: mkwlppr target-file.xml [duration] pic1 pic2 [pic3 .. picN]"
  8. else
  9.   files=$*
  10.   #Grab the name of the target xml file
  11.   xmlfile=$(echo $files | cut -d " " -f 1)
  12.   #remove the first item from $files
  13.   files=$(echo $files | sed 's/^\<[^ ]*\>//')
  14.   if [ "$(echo $xmlfile | grep '\.xml$')" = "" ]; then
  15.     echo "Your target file must be an XML file"
  16.   else
  17.     inputIsValid="true";
  18.     firstItem=$(echo $files | cut -d " " -f 1)
  19.     duration="1795.0";#set the default duration
  20.     if [ "$(echo $firstItem | grep '^[0-9]\+\.[0-9]\+$')" != "" ]; then
  21.       echo "The duration must be an integer"
  22.       files=$(echo $files | sed 's/^\<[^ ]*\>//')
  23.       inputIsValid=""
  24.     elif [ "$(echo $firstItem | grep '^[0-9]\+$')" != "" ]; then
  25.       #If the item is a number, then use it as the duration for each wallpaper image
  26.       duration="$(expr $firstItem - 5).0"
  27.       #remove the duration from the list of files
  28.       files=$(echo $files | sed 's/^\<[^ ]*\>//')
  29.     fi
  30.     if [ "$files" = "" ]; then
  31.       echo "You must enter image files to associate with the XML file"
  32.     else
  33.       for file in $files
  34.       do
  35.         if [ ! -f $file ]; then
  36.           echo "\"$file\" does not exist"
  37.           inputIsValid="";
  38.         elif [ "$(echo $file | sed 's/^.*\.\(jpg\|jpeg\|bmp\|png\|gif\|tif\|tiff\|jif\|jfif\|jp2\|jpx\|j2k\|j2c\)$//')" != "" ]; then
  39.           echo "\"$file\" is not an image file"
  40.           inputIsValid=""
  41.         fi
  42.       done
  43.       if [ $inputIsValid ]; then
  44.         currDir=$(pwd)
  45.         echo "<background>" >> $xmlfile
  46.         echo "  <starttime>\n    <year>2009</year>\n    <month>08</month>\n    <day>04</day>" >> $xmlfile;
  47.         echo "    <hour>00</hour>\n    <minute>00</minute>\n    <second>00</second>\n  </starttime>" >> $xmlfile;
  48.         echo "  <!-- This animation will start at midnight. -->" >> $xmlfile
  49.         firstFile=$(echo $files | cut -d " " -f 1) # grab the first item
  50.         if [ "$(echo $firstFile | sed 's/\(.\).*/\1/')" != "/" ]; then
  51.           #If the first character in the filename is not '/', then it is a relative path and must have the current directory's path appended
  52.           firstFile="$currDir/$firstFile"
  53.         fi
  54.         firstFile=$(echo $firstFile | sed 's/[^/]\+\/\.\.\/\?//g');#Remove occurrences of ".." from the filepath
  55.         files=$(echo $files | sed 's/^\<[^ ]*\>//') # remove the first item
  56.         prevFile=$firstFile
  57.         currFile=""
  58.         #TODO add absolute path to the filenames
  59.         #if $currFile =~ "^/.*" then the file needs to path appended
  60.         echo "  <static>\n    <duration>$duration</duration>\n    <file>$firstFile</file>\n  </static>" >> $xmlfile
  61.         for currFile in $files; do
  62.           if [ "$(echo $currFile | sed 's/\(.\).*/\1/')" != "/" ]; then
  63.             #If the first character in the filename is not '/', then it is a relative path and must have the current directory's path appended
  64.             currFile="$currDir/$currFile"
  65.           fi
  66.           currFile=$(echo $currFile | sed 's/[^/]\+\/\.\.\/\?//g') # Remove occurrences of ".." from the filepath
  67.           echo "  <transition>\n    <duration>5.0</duration>\n    <from>$prevFile</from>\n    <to>$currFile</to>\n  </transition>" >> $xmlfile;
  68.           echo "  <static>\n    <duration>$duration</duration>\n    <file>$currFile</file>\n  </static>" >> $xmlfile;
  69.           prevFile=$currFile
  70.         done
  71.         echo "  <transition>\n    <duration>5.0</duration>\n    <from>$currFile</from>\n    <to>$firstFile</to>\n  </transition>" >> $xmlfile;
  72.         echo "</background>" >> $xmlfile;
  73.       fi
  74.     fi
  75.   fi
  76. fi
RAW Paste Data
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy. OK, I Understand
 
Top