Skip to content
This repository

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
tree: c5adc505d7
Fetching contributors…

Cannot retrieve contributors at this time

executable file 32 lines (26 sloc) 1.058 kb
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
#!/home/gregf/.rvm/rubies/ruby-1.9.2-p0/bin/ruby
# vim: set sw=2 sts=2 et tw=80 :

WALLPAPER="/home/gregf/media/wallpaper/new/" # Full path no ~
IMAGE_FORMATS="[.jpg,.gif,.png,.bmp]" # Keep this a string
WALLPAPER_CMD="/usr/bin/feh" # Whatever command you use to set your wallpaper
WPCMD_OPTIONS="--bg-scale" # Any options you need to pass to the above command
DISPLAY=":0.0" # You can use ENV['DISPLAY'] here but, it wont work from a cronjob.

unless IMAGE_FORMATS.class == String
  puts "IMAGE_FORMATS must be a string, surround it in quotes."
  exit
end

unless File.directory?("#{WALLPAPER}")
  puts "Wallpaper directory #{WALLPAPER} does not exist"
  exit
end

unless File.executable?("#{WALLPAPER_CMD}")
  puts "#{WALLPAPER_CMD} is not executable"
  exit
end

ENV["DISPLAY"] = "#{DISPLAY}"

Dir.chdir("#{WALLPAPER}") do
  files = Dir.glob("*#{IMAGE_FORMATS}")
  #puts random_file = rand(1-files.size) # 1.8.6
  random_file = Random.new.rand(1..files.size) # requires ruby 1.9.2
  IO.popen("#{WALLPAPER_CMD} #{WPCMD_OPTIONS} #{files[random_file]}")
end
Something went wrong with that request. Please try again.