Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- ## Removes previous wallpaper file, and gets new image from Windows Spotlight
- require 'fileutils'
- require 'exifr/jpeg'
- SPOTLIGHT_IMAGES_PATH = File.join(ENV["LocalAppData"].split('\\') + ["Packages", "Microsoft.Windows.ContentDeliveryManager_cw5n1h2txyewy", "LocalState", "Assets"])
- WALLPAPER_FILENAME_FILE = "currect_wallpaper_filename.txt"
- spotlight_image_path = Dir[File.join(SPOTLIGHT_IMAGES_PATH, "*")]
- .select{|f| File.size(f) > 50e3 }
- .select do |f|
- exif = EXIFR::JPEG.new(f)
- exif.width == 1920 && exif.height == 1080
- rescue
- false
- end
- .sample
- if spotlight_image_path
- begin
- old_wallpaper_filename = File.read(WALLPAPER_FILENAME_FILE)
- if old_wallpaper_filename && !old_wallpaper_filename.empty?
- old_wallpaper_path = File.join(Dir.pwd, old_wallpaper_filename)
- FileUtils.rm_f(old_wallpaper_path)
- end
- rescue
- end
- new_wallpaper_name = File.basename(spotlight_image_path) + ".jpg"
- dest_path = File.join(Dir.pwd, new_wallpaper_name)
- File.write(WALLPAPER_FILENAME_FILE, new_wallpaper_name)
- FileUtils.cp(spotlight_image_path, dest_path)
- end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement