Skip to content
Newer
Older
100755 33 lines (26 sloc) 1.03 KB
f48a939 New Import
Greg Fitzgerald authored Nov 1, 2010
1 #!/home/gregf/.rvm/rubies/ruby-1.9.2-p0/bin/ruby
2 # vim: set sw=2 sts=2 et tw=80 :
3
4 WALLPAPER="/home/gregf/media/wallpaper/new/" # Full path no ~
5 IMAGE_FORMATS="[.jpg,.gif,.png,.bmp]" # Keep this a string
6 WALLPAPER_CMD="/usr/bin/feh" # Whatever command you use to set your wallpaper
7 WPCMD_OPTIONS="--bg-scale" # Any options you need to pass to the above command
8 DISPLAY=":0.0" # You can use ENV['DISPLAY'] here but, it wont work from a cronjob.
9
10 unless IMAGE_FORMATS.class == String
11 puts "IMAGE_FORMATS must be a string, surround it in quotes."
12 exit
13 end
14
15 unless File.directory?("#{WALLPAPER}")
16 puts "Wallpaper directory #{WALLPAPER} does not exist"
17 exit
18 end
19
20 unless File.executable?("#{WALLPAPER_CMD}")
21 puts "#{WALLPAPER_CMD} is not executable"
22 exit
23 end
24
25 ENV["DISPLAY"] = "#{DISPLAY}"
26
27 Dir.chdir("#{WALLPAPER}") do
28 files = Dir.glob("*#{IMAGE_FORMATS}")
29 #puts random_file = rand(1-files.size) # 1.8.6
30 random_file = Random.new.rand(1..files.size) # requires ruby 1.9.2
31 IO.popen("#{WALLPAPER_CMD} #{WPCMD_OPTIONS} #{files[random_file]}")
32 end
Something went wrong with that request. Please try again.