Advertisement
Guest User

Random wallpaper shuffle

a guest
Oct 19th, 2014
306
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 1.25 KB | None | 0 0
  1. -- {{{ Function definitions
  2.  
  3. -- scan directory, and optionally filter outputs
  4. function scandir(directory, filter)
  5.     local i, t, popen = 0, {}, io.popen
  6.     if not filter then
  7.         filter = function(s) return true end
  8.     end
  9.     print(filter)
  10.     for filename in popen('ls -a "'..directory..'"'):lines() do
  11.         if filter(filename) then
  12.             i = i + 1
  13.             t[i] = filename
  14.         end
  15.     end
  16.     return t
  17. end
  18.  
  19. -- }}}
  20.  
  21. -- configuration - edit to your liking
  22. wp_index = 1
  23. wp_timeout  = 60
  24. wp_path = "/home/danimal/Wallpapers/"
  25. wp_filter = function(s) return string.match(s,"%.png$") or string.match(s,"%.jpg$") end
  26. wp_files = scandir(wp_path, wp_filter)
  27.  
  28. -- setup the timer
  29. wp_timer = timer { timeout = wp_timeout }
  30. wp_timer:connect_signal("timeout", function()
  31.  
  32. -- set wallpaper to current index for all screens
  33. for s = 1, screen.count() do
  34. gears.wallpaper.maximized(wp_path .. wp_files[wp_index], s, true)
  35. end
  36.  
  37. -- stop the timer (we don't need multiple instances running at the same time)
  38. wp_timer:stop()
  39.  
  40. -- get next random index
  41. wp_index = math.random( 1, #wp_files)
  42.  
  43. --restart the timer
  44. wp_timer.timeout = wp_timeout
  45. wp_timer:start()
  46. end)
  47.  
  48. -- initial start when rc.lua is first run
  49. wp_timer:start()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement