Archive for June, 2008

New tool: sednames

Friday, June 20th, 2008

What if you could use sed to rename files?

Well, now you can.

sednames is a utility that lets you specify a program for sed on the command-line, which it then uses to rename the files that you also specify on the command-line.

The twist is that, unlike other batch-renamers, sednames also supports your VCS. For the most common cases (svn, hg, bzr, and git), there's a --vcs option:

% sednames -e 's/Replace/Mix/' --vcs=hg *

This command-line will use Mercurial (hg mv) to rename every file by replacing “Replace” with “Mix”. Of course, if a name doesn't contain “Replace”, then that name will be unchanged and sednames is smart enough to not try to rename that file.

Not only that, but just in case you're using some oddball VCS (or you want to copy instead of rename, or something), sednames supports using any program to rename your files, as long as it accepts both the before and after names in its arguments. The --help output is more specific, but to put it simply, it works similarly to find's -exec option.

You can download the current revision directly, or use the Mercurial repository to follow or contribute to its development.

Free stuff on iTunes: Cable TV

Tuesday, June 17th, 2008

From the podcast directory, some free cable TV talk shows. All of these carry (what appear to be) full episodes:

Note: I don't endorse any of these shows, and purposefully listed them in alphabetical order.

What to do if Python says “character mapping must return integer, None or unicode”

Monday, June 16th, 2008

So you're using the unicode class's translate method, and it says:

TypeError: character mapping must return integer, None or unicode

You may be wondering what causes this. After all, you're duly using the string.maketrans function. Surely this should be valid?

Well, no: You can only use string.maketrans with str.translate. For unicode.translate, you must use a different kind of translation table:

… a mapping of Unicode ordinals to Unicode ordinals [int], Unicode strings [unicode] or None.

3.6.1 String Methods

In Localization Helper, I had to replace my string.maketrans call with this code:

dict(zip(map(ord, u'\a\b\t\n\v\f\r'), u'abtnvfr'))

Note that I need to call ord on each key character, because keys must be ints.

New tool: Localization Helper

Monday, June 16th, 2008

One thing that I noticed a few days ago while working on Growl 1.1.4 is that some strings aren't translated in a couple of the localizations. I reported this on our localization mailing list, but it got me thinking: I could really use a program that would scan a tree of source code and tell me of problems like this.

So I wrote one.

Localization Helper is a command-line tool to walk a tree of source code looking for .strings files, and compare different localizations of them. It reports duplicate (not-translated) strings, and will soon (maybe by the time you read this) report strings that are missing altogether.

Currently, it only compares all other languages to one primary language, which defaults to English. I didn't feel like making it compare every language to every other language. ☺

The program scans every directory you specify on the command-line. If you don't give it any arguments, it scans the current working directory. Also, it has some options, which you can see with the --help option.

Here are some excerpts of its output for the Growl 1.1.3 source code:

*** Found problems in Core/Resources/*.lproj/Localizable.strings
Duplicate strings in Localizable.strings between English.lproj and cs.lproj:
"User went idle" = "User went idle";
"You are now considered idle by Growl" = "You are now considered idle by Growl";
"No activity for more than %d seconds." = "No activity for more than %d seconds.";
"Growl was unable to create the socket for Network notifications." = "Growl was unable to create the socket for Network notifications.";
"You are no longer considered idle by Growl" = "You are no longer considered idle by Growl";
⋮
!!! Warning: Localized file Extras/GrowlSafari/de.lproj/InfoPlist.strings is missing
!!! Warning: Localized file Extras/GrowlSafari/ja.lproj/InfoPlist.strings is missing

*** Could not read plist file at path Extras/GrowlSafari/de.lproj/Localizable.strings
*** Could not read plist file at path Extras/GrowlSafari/ja.lproj/Localizable.strings
*** Could not read plist file at path Extras/GrowlSafari/pt_BR.lproj/Localizable.strings
*** Could not read plist file at path Extras/GrowlSafari/sv.lproj/Localizable.strings

You'll need to have either Leopard or Python 2.5 + PyObjC (Leopard comes with both) to use the program. (BTW: PyObjC rocks.)

Until I release it sometime later this week (hopefully), I provide two ways to get the program:

  1. You can download it directly.
  2. You can clone my repository: hg clone http://boredzo.org/localization-helper/hg/

Of course, if you clone your repository, then you can easily get updates by running hg pull.

Also, there's a commits feed, in case you want to stay on top of localization_helper's development using your feed reader.

Growl 1.1.3

Friday, June 6th, 2008

I just released version 1.1.3 of Growl. Some highlights from the version history:

  • Worked around conflict with Logitech Control Center 2.4, and implemented countermeasures in case another input-manager hack in the future has the same bug
  • Show notifications on every Space (Leopard)
  • Rewrote GrowlMail to fix conflict between it and Leopard, and make it much more robust for the future
  • Updated GrowlSafari to work with Safari 3.0 and later (thanks to Ben Willmore)
  • Fixed growlnotify to actually send the notification on Leopard
  • Fixed a hang on changing the default display
  • Fixed displaying a close widget on mouse-over

Those aren't the only improvements, but they're the most major. Growl and its extras are finally completely Leopard-ready.

You can download 1.1.3 either from the About tab in the Growl preference pane, or from the website.

In other news, this is my first release as the Lead Developer of Growl. I'm replacing Brian Ganninger, who was (IIRC) Lead Developer for the entire 1.1 series. Let us all thank him for his excellent work, and wish him well for the future.

WWDC Survival Guide

Thursday, June 5th, 2008

I'm not attending WWDC this year (sorry!), but I did attend last year, so I have some advice for those of you attending for the first time (and I hear there are a lot of you).

  1. Walk.

    San Francisco isn't designed to handle car traffic—it's optimized for pedestrians, in several ways:

    • Most streets are one-way, meaning that a car must take a longer route than a pedestrian can.
    • The walk/don't walk signals don't have buttons, because you don't need them. When drivers get the green light, pedestrians get the walk signal—every time.
    • Almost all parking costs money per hour. Walking is free.
    • Parking is so sparse that you'll walk one or more blocks anyway. So, if you can walk from your hotel to Moscone and back, do so. You'll get there faster and more cheaply.
  2. Don't eat the lunch.

    The objects that Moscone serves as lunch are not food. Food, by definition, is edible. Eat out.

    Note that I'm only talking about lunch. Moscone serves food at other times of day: a mid-afternoon snack, and dinner. These are OK, and sometimes even pretty good. Only the lunch is inedible.

  3. Attend parties, or make your own.

    If you're at WWDC with some friends or colleagues, you may be able to work on some code with them at the conference. This is a lot of fun, especially if you can get together around a power strip.

    Either way, you may want to attend other parties. Some parties are listed on Upcoming. Additionally, there's CocoaHeads meeting at the Apple Store on Stockton St on Tuesday. If you know any others, please post a comment here and I'll link to them. (However, I'd stay away from the Thirsty Bear pub. The acoustics in that place are terrible. Forget conversation.)

  4. Bring your (US) AC adapter.

    They have charging stations at the conference, but the week I was there, the MBP chargers were broken. They never did get them fixed. I ended up buying a second AC adapter at the Apple Store.

    Additionally, Tim Burks recommends bringing a power strip—a good idea if you and your friends/colleagues intend to hack code together at the conference. More specifically, Mark Boszko recommends Monster Cable's (yes, them) Outlets to Go. He also notes the existence of 3- and 6-outlet versions, which you may prefer, depending on how much space you have in your bag.

  5. Grab a copy of The Onion.

    You may or may not know this, but The Onion is not just a website and series of books—it really does exist as a newspaper. It's available for free in newspaper racks in select cities, including San Francisco. I'm sorry, but I don't remember where the rack I got mine from was—I think it was on Market Street, but I don't remember the cross-street.

Some good eating places:

Enjoy the WWDC!

Also, be sure to read the comments on this post! Already, Jonathan Wight has made two very wise suggestions. You may also want to check back periodically so you don't miss any.