Create a gist now

Instantly share code, notes, and snippets.

fix Mail keyboard shortcuts containing > in Lion
#!/usr/bin/env ruby
require 'rubygems'
require 'cfpropertylist'
# This is a fix for the bug filed as Radar #1288404 with Apple.
# http://openradar.appspot.com/radar?id=1288404
# So, in Snow Leopard, I always set up Mail.app to have keyboard shortucts
# for my "From" email addresses. You can create your own in the Keyboard
# system preference pane by entering your email address (like "Andre Arko
# <andre@arko.net>") as the Menu Title. I used ⌃1, ⌃2, etc for each of my
# email addresses, so I could change which address the email would be sent
# from. Lion introduces a new bug that corrupts any keyboard shortcut whose
# menu title contains an angle bracket. The menu title loses the closing
# angle bracket, and gains the character "\e" at the beginning and end. This
# happens any time you open the Keyboard prefpane to change any other
# shortcut, which is really annoying. So I wrote this script to
# automatically fix my Mail shortcuts after I've done that.
paths = []
paths << "~/Library/Preferences/com.apple.mail.plist"
paths << "~/Library/Preferences/com.sparrowmailapp.sparrow.plist"
paths.each do |path|
path = File.expand_path(path)
plist = CFPropertyList::List.new(:file => path)
prefs = CFPropertyList.native_types(plist.value)
user_keys = prefs["NSUserKeyEquivalents"]
user_keys.keys.each do |key|
shortcut = user_keys.delete(key)
fixed_key = key.gsub(/\e(.*?)\e/, '\1>')
user_keys[fixed_key] = shortcut
end
File.open(path, "w"){|f| f.write(prefs.to_plist) }
`plutil -convert binary1 '#{path}'`
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment