Skip to content

Instantly share code, notes, and snippets.

@saetia
Last active November 26, 2022 03:17
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save saetia/6443678 to your computer and use it in GitHub Desktop.
Save saetia/6443678 to your computer and use it in GitHub Desktop.
Save web image as wallpaper
#/usr/bin/env ruby
require 'nokogiri'
require 'open-uri'
doc = Nokogiri::HTML(open('https://medium.com'))
urls = doc.at_css('.cover-img')["style"].scan(/\('([^\)]*)'\)/)
image_src = 'http:'+urls[0][0]
ext = image_src.split('.').last
random = rand(2**256).to_s(36)[0..7]
download_path = "/tmp/#{random}.#{ext}"
puts "downloading: #{image_src} to #{download_path}\n"
`wget -O #{download_path} #{image_src}`
`osascript -e 'tell application "System Events" to set picture of every desktop to "#{download_path}"'`
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment