Created
December 13, 2010 22:30
-
-
Save paulcarey/739714 to your computer and use it in GitHub Desktop.
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
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 | |
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