One of the most aggravating things when I switched to Linux Mint 12 from Mint 10 was that it seemed to offer a step backwards for a lot of functionality. I was using a program called “Desktop Drapes” to periodically cycle my wallpaper, but it no longer worked in Gnome 3. (there were some supposed plugins to fix this but they didn’t work). I tried a few others, but they universally failed.
So I ended up writing a python script to do the job:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 |
#!/usr/bin/python #Copyright (c) 2011 BASeCamp Corporation # All rights reserved. # # Redistribution and use in source and binary forms, with or without # modification, are permitted provided that the following conditions # are met: # # Redistributions of source code must retain the above copyright notice, # this list of conditions and the following disclaimer. # # Redistributions in binary form must reproduce the above copyright # notice, this list of conditions and the following disclaimer in the # documentation and/or other materials provided with the distribution. # # Neither the name of the project's author nor the names of its # contributors may be used to endorse or promote products derived from # this software without specific prior written permission. # # THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS # "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT # LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS # FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT # HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, # SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED # TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR # PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF # LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING # NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS # SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. import sys,os,random,ConfigParser,string from optparse import OptionParser #Wallpaper cycling script #written Sunday March 18th 2012 #designed to be added to crontab with a delay #example line in crontab: #*/4 * * * * /home/bc_programming/bin/cyclebg.py #when run, it will change the wallpaper to the next one in the cycle and exit. #Author: BC_Programming #location of data path. we keep track of the wallpapers we have already cycled there. datapath = os.path.expanduser("~/.cyclebg/") datafile = datapath + "cycled_data.dat" wallpaperfile = datapath + "wallpapers.dat" disablefile = datapath + "disable.dat" #if this file exists we are "disabled" and don't change the wallpaper. #command to run to change the bg. #following is for Gnome 2 #bgchangecmd = 'dconf gsettings set org.gnome.desktop.background picture-uri "file://%s"' #gnome 3 command... bgchangecmd = 'gsettings set org.gnome.desktop.background picture-uri "file:///%s"' #we need two lists: the list of possible wallpapers, and the wallpapers we've already listed. def isdisabled(): return os.path.exists(disablefile) #returns the list of wallpapers we've already cycled through. def getusedlist(): if not os.path.exists(datafile): #if the file doesn't exist, then return an empty list. return [] else: return list(open(datafile)) #clears the used wallpapers list. def clearused(): if os.path.exists(datafile): os.remove(datafile) def markused(wallpaper): #mark a wallpaper as viewed writelist = open(datafile,'a') writelist.write(wallpaper) #returns all the wallpapers we are to cycle through. def getwallpapers(): if not os.path.exists(wallpaperfile): return [] else: return list(open(wallpaperfile)) #routine that changes the background. def changebackground(picture): #changes the background to the specified image. cmdrun =bgchangecmd cmdrun = cmdrun.replace("%s",picture) print " running ",cmdrun os.system(cmdrun) def main(): if isdisabled(): sys.exit(2) sys.exit(changewallpaper()) def changewallpaper(): #retrieve the wallpapers and used wallpapers... used = getusedlist() papers = getwallpapers() #exit if no wallpapers in main list... if len(papers)==0: print "No wallpapers! add wallpaper file paths to ", wallpaperfile, "!" return 1 #now, remove all entries in papers that exist in used. removethese=[] #list of items to remove for iterateused in papers: if iterateused in used: removethese = removethese + [iterateused] #now, remove the items... for iterateremove in removethese: papers.remove(iterateremove) if len(papers)==0: #if papers list is empty, egads! clear the used list, since we've cycled through them all evidently. clearused() #and... well balls to it we'll just call ourself. changewallpaper() #now, the main logic. Choose a wallpaper... choosefrom = papers #shuffle the choosefrom listing... random.shuffle(choosefrom) #take one of the items from the resulting shuffled list. chosen = choosefrom.pop() #add it to the list of seen wallpapers... markused(chosen) #and attempt to change to it... changebackground(chosen) return 0 #parse our options/arguments... parser = OptionParser(usage="usage: %prog [options] ", version="%prog 1.0") parser.add_option("-g","--gui", action="store_true", dest="gui", default=False, help="run GUI") global options,args (options,args) = parser.parse_args(); main() |
The script is designed to be used by adding a like to crontab.
Have something to say about this post? Comment!
One thought on “Wallpaper Change Script: Gnome 3”
So this is the background changer script you’ve been talking about earlier? Interesting.