Skip to content

Instantly share code, notes, and snippets.

@dheaney
Last active January 2, 2016 23:09
Show Gist options
  • Select an option

  • Save dheaney/8374507 to your computer and use it in GitHub Desktop.

Select an option

Save dheaney/8374507 to your computer and use it in GitHub Desktop.
Set your Gravatar account image to your Address Book entry on your Mac.
<!-- Copyright (c) 2012 David Heaney -->
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
<plist version="1.0">
<dict>
<key>KeepAlive</key>
<false/>
<key>Label</key>
<string>com.dejay.gravatarmac</string>
<key>ProgramArguments</key>
<array>
<string>/usr/local/bin/gravatar</string>
<string><%= email %></string>
</array>
<key>RunAtLoad</key>
<true/>
</dict>
</plist>
#!/usr/local/bin/macruby
# Copyright (c) 2012 - 2014 David Heaney
require 'digest/md5'
require 'net/http'
framework "ScriptingBridge"
name = ENV['USER']
book = SBApplication.applicationWithBundleIdentifier("com.apple.addressbook")
download = "/Library/Caches/Gravatar/#{name}/#{name}.png"
begin; Dir.mkdir("/Library/Caches/Gravatar/#{name}"); rescue
Net::HTTP.start("gravatar.com/") do |http|
resp = http.get("/avatar/#{Digest::MD5.hexdigest(ARGV.first.downcase)}")
open(download, "wb") do |file|
file.write(resp.body)
end
end
data = NSImage.alloc.initWithContentsOfFile(download)
book.myCard.setImage(data)
# Copyright (c) 2012 David Heaney
require 'erb'
UNAME = ENV['USER']
AGENT = "/Users/#{UNAME}/Library/LaunchAgents/com.dejay.gravatar-mac.plist"
desc "Install Gravatar-Mac!"
task :install do
puts "Please enter the email that you wish to use for Gravatar-Mac:"
email = STDIN.gets.chomp
system "sudo cp bin/gravatar /usr/local/bin/gravatar"
system "sudo chmod +x /usr/local/bin/gravatar"
plist = "com.dejay.gravatarmac.plist"
agent_dir = File.expand_path("~/Library/LaunchAgents/")
agent = File.join(agent_dir, plist)
Dir.mkdir(agent_dir) unless File.exists?(agent_dir)
File.open(agent, "w") do |f|
f.puts ERB.new(IO.read(plist)).result(binding)
end
puts "Done!"
end
desc "Uninstall Gravatar-Mac (BOOO!)"
task :uninstall do
system "sudo rm /usr/local/bin/gravatar"
system "rm /Users/#{UNAME}/Library/LaunchAgents/com.dejay.gravatar-mac.plist"
puts "Done!"
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment