Skip to content

Instantly share code, notes, and snippets.

@tensorpudding
Created February 9, 2010 08:34
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
  • Save tensorpudding/299024 to your computer and use it in GitHub Desktop.
Save tensorpudding/299024 to your computer and use it in GitHub Desktop.
#!/usr/bin/ruby
############################################################
# Simple wallpaper-rotation script. You can run it in cron.#
############################################################
#
# Defaulting parameters which can be specified at the CLI
#
command = ARGV[0]
command ||= "/usr/bin/feh --bg-scale"
dir = ARGV[1]
dir ||= "/home/michael/wall/default/"
#
# Selects proper wallpaper randomly from the images in the directory
#
wallpapers = (Dir.new dir).entries.select do |entry|
[".jpg", ".png", ".jpeg"].include? File.extname(entry)
end
choice = wallpapers[rand(wallpapers.length)]
#
# Now it actually sets the wallpaper
#
%x{ #{ command } "#{ File.join(dir, choice) }" } unless choice.empty?
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment