Skip to content

Embed URL

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Switch between two desktop images on OS X e.g. a standard image and a texture for use behind transparent windows like Terminal or MacVim
#!/usr/bin/env ruby
STD_IMG_REF = '/Users/paulcarey/.std_desktop_image.txt'
IMG_SRC = '/Users/paulcarey/dev/images/ir_black_bg.png'
def current_img
cmd = "defaults read com.apple.Desktop Background | grep ImageFilePath | tail -n 2 | head -n 1"
res = `#{cmd}`
res = res.split('=')[1].strip
res[1, res.size - 3]
end
def save_current_img
File.open(STD_IMG_REF, 'w+') { |f| f.puts current_img }
end
def load_prev_img
File.open(STD_IMG_REF, 'r') { |f| f.gets.strip }
end
def set_img src
script = %Q<tell application "Finder"
set desktop picture to POSIX file "#{src}"
end tell>
IO.popen('osascript -', 'w') { |p| p.puts script }
end
if current_img == IMG_SRC
set_img load_prev_img
else
save_current_img
set_img IMG_SRC
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Something went wrong with that request. Please try again.