Create a gist now

Instantly share code, notes, and snippets.

What would you like to do?
fix Mail keyboard shortcuts containing > in Lion
#!/usr/bin/env ruby
require 'rubygems'
require 'plist'
# This is a fix for the bug filed as Radar #1288404 with Apple.
# So, in Snow Leopard, I always set up 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
# <>") 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.
path = File.expand_path("~/Library/Preferences/")
# Convert to XML plist so the plist gem can read it
system("plutil -convert xml1 '#{path}'")
# Parse the plist into a hash
prefs = Plist.parse_xml(path)
# Gsub away the buggy values from the Lion Keyboard.prefpane
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
# Write out the fixed plist as XML, "w"){|f| f.write(prefs.to_plist) }
# Convert the XML plist back to binary for
system("plutil -convert binary1 '#{path}'")

jbenet commented Sep 19, 2011

Thank you for writing this!

Check out for binary plist + sparrow support.


indirect commented Sep 19, 2011

oh; right. I had fixed this to handle binary plists, but forgot to update the gist. thanks for the reminder!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment