Created
August 8, 2011 07:39
-
-
Save indirect/1131361 to your computer and use it in GitHub Desktop.
fix Mail keyboard shortcuts containing > in Lion
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 | |
require 'rubygems' | |
require 'plist' | |
# 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 | |
# <[email protected]>") 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/com.apple.mail.plist") | |
# 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 | |
end | |
# Write out the fixed plist as XML | |
File.open(path, "w"){|f| f.write(prefs.to_plist) } | |
# Convert the XML plist back to binary for Mail.app | |
system("plutil -convert binary1 '#{path}'") |
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
Thank you for writing this!
Check out https://gist.github.com/1225867/c72395db3b9623bdbdb71db0d6973e8321ec9ef2 for binary plist + sparrow support.