Advertisement
Guest User

Untitled

a guest
Sep 19th, 2019
100
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.08 KB | None | 0 0
  1. ## Removes previous wallpaper file, and gets new image from Windows Spotlight
  2.  
  3. require 'fileutils'
  4. require 'exifr/jpeg'
  5.  
  6. SPOTLIGHT_IMAGES_PATH = File.join(ENV["LocalAppData"].split('\\') + ["Packages", "Microsoft.Windows.ContentDeliveryManager_cw5n1h2txyewy", "LocalState", "Assets"])
  7. WALLPAPER_FILENAME_FILE = "currect_wallpaper_filename.txt"
  8.  
  9. spotlight_image_path = Dir[File.join(SPOTLIGHT_IMAGES_PATH, "*")]
  10. .select{|f| File.size(f) > 50e3 }
  11. .select do |f|
  12. exif = EXIFR::JPEG.new(f)
  13. exif.width == 1920 && exif.height == 1080
  14. rescue
  15. false
  16. end
  17. .sample
  18.  
  19.  
  20. if spotlight_image_path
  21. begin
  22. old_wallpaper_filename = File.read(WALLPAPER_FILENAME_FILE)
  23. if old_wallpaper_filename && !old_wallpaper_filename.empty?
  24. old_wallpaper_path = File.join(Dir.pwd, old_wallpaper_filename)
  25. FileUtils.rm_f(old_wallpaper_path)
  26. end
  27. rescue
  28. end
  29.  
  30. new_wallpaper_name = File.basename(spotlight_image_path) + ".jpg"
  31. dest_path = File.join(Dir.pwd, new_wallpaper_name)
  32. File.write(WALLPAPER_FILENAME_FILE, new_wallpaper_name)
  33. FileUtils.cp(spotlight_image_path, dest_path)
  34. end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement