Created
March 6, 2009 14:19
-
-
Save youpy/74919 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/bin/env ruby | |
# * * * * * bijin_wallpaper.rb | |
require 'pathname' | |
require 'open-uri' | |
require 'fileutils' | |
include FileUtils | |
IMAGE_DIR = '/Users/youpy/Documents/bijint' | |
def main | |
now = Time.now | |
image_path = image_path(now) | |
mkdir_p image_path.dirname | |
unless image_path.exist? | |
File.open(image_path, "w") do |f| | |
open(image_url(now)) do |img| | |
f.write img.read | |
end | |
end | |
end | |
set_desktop_picture(image_path) | |
end | |
def image_path(now) | |
Pathname.new(IMAGE_DIR) + '%s.jpg' % now.strftime('%H%M') | |
end | |
def image_url(now) | |
'http://www.bijint.com/jp/img/photo/%s.jpg' % now.strftime('%H%M') | |
end | |
def set_desktop_picture(path) | |
IO.popen("osascript", "r+") do |io| | |
io.puts <<END | |
tell application "Finder" | |
set pFile to POSIX file "#{path}" as string | |
set current to desktop picture as string | |
if current is not pFile then | |
set desktop picture to file pFile | |
end if | |
end tell | |
END | |
end | |
end | |
main |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment