Fixing Filenames

I use SoundJuicer to rip my music CDs into Ogg files, and play them in Rhythmbox.

Both programs work great, with the exception of stripping special characters–like ‘,’ ‘<‘ or ‘#’–from filenames. SoundJuicer has an option marked “Strip Special Characters,” but it doesn’t always work. Some special characters–anything with an accent mark above it, for instance–it won’t ever strip. Since Rhythmbox chokes on filenames with special characters, you have to change the filename before it’ll play the file.

This is tedious to do manually, so I wrote a Python script to do it for me. It’s not very elegant, but it gets the job done: invoke it from the command line followed by a path to the directory containing the files you need stripped of special characters, and it takes care of the rest.

Here’s the code:

# This is a simple python program to look through a directory and
# strip special characters from the filenames in that directory. I use
# it mostly to fix filenames after importing music from CDs.

# Invoke this program from the command line followed by the path to the directory
# containing the filenames you want fixed.
# Copyright (C) 2008 Ron Toland
# This program is free software: you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation, either version 3 of the License, or
# (at your option) any later version.
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# GNU General Public License for more details.
# You should have received a copy of the GNU General Public License
# long with this program. If not, see <;.

import os, sys

def namefixer(dummy, dirname, filesindir):
for fname in filesindir:
newname = fname.replace(‘ ‘, ‘_’)
newname2 = newname.replace(‘,’, ”)
newname3 = newname2.replace(‘+’, ‘_’)
newname4 = newname3.replace(‘-‘, ‘_’)
newname5 = newname4.replace(‘#’, ‘no’)
newname6 = newname5.replace(‘>’, ‘gt’)
newname7 = newname6.replace(‘<‘, ‘lt’)
os.rename(os.path.join(dirname, fname), os.path.join(dirname, newname7))

if __name__ == ‘__main__’:
os.path.walk(sys.argv[1], namefixer, None)

Save this file as “” somewhere in your home directory, then use “chmod a+x” to make it executable. To make it extra easy to use, create a link like this:

“sudo ln -s <full path to> /usr/local/bin/namefixer”

That’ll create a link file in your usr/local/bin folder that’ll let you invoke the program from any directory just by typing: “namefixer <path to directory you want fixed>

I’m still working on getting to get rid of accented characters. When I figure it out, I’ll post the corrected code. Should any of you, dear readers, get it working first, please let me know!


A friend recently wrote to me about encountering her first instance of racism directed against her, because she isn’t Jewish.

I started to reply with: “I’m surprised you’d find such prejudice alive and well in a Blue State, in the 21st century,” but stopped myself. How could I write those words? They’re a trite response that only someone who has never experienced discrimination, never been made to feel different and excluded, could write.

The truth is that prejudice is alive and well in the U.S. Until I worked at the Goddard Space Flight Center, I never realized how pervasive stereotypes really are, and how double-edged they can be. If a black person is passed over for a promotion, was it because they weren’t the best, or because they’re black? If that same person had been promoted, the question would still have come up: were they promoted just because they’re black? That’s a weight I would go crazy trying to bear; it’s hard enough trying to succeed in any field without having to wonder if your success is real, or being suppressed, or not.

I always thought discrimination would be something I’d experience from the outside, until I started telling people I was an atheist. I’ve had several people try to convince me I was not an atheist, because I’m too nice to not believe in God! One woman I told didn’t even know what an atheist was.

Now, I’ve not been spit on, or cursed, or denied a job because of my non-religion. But I have felt completely out of place, especially when people assume I’m a devout Christian just because I’m a white male. I feel a little like an unwilling spy, moving among people that would probably not even look at me if they knew my religious beliefs. I can still catch a taxi, but every time I do I wonder about those that can’t, just because their difference is easier to see.

Despite my “liberal” education, my own prejudices run parallel and opposite to the bias I encounter. Fundamentalists make me distinctly uncomfortable, and it’s normally hard for me to have a serious conversation with them without getting angry. If I ran a business, I wouldn’t really want them as customers. If I were choosing babysitters, I’d cross the devout off my list. The fact that the President of the United States thinks God talks to him scares the ever-lovin’ sh*t out of me. It’s something I struggle with: to acknowledge their right to believe as they wish while I fight against every consequence of their beliefs.

What are your prejudices? When you call technical support, do you feel better if a man answers your call? If you’re white and enter a mall where most of the customers are black, do you stay as long to shop? If you’re an atheist, would you vote for a fundamentalist Christian?

Political Matchmaking

Took the matchmaking survey offered by Glassbooth. Their survey won’t find your soulmate; it’s designed to find the presidential candidate whose stance on the issues matches your own.

My results?  Seems Dennis Kucinich (D) is my best bet.  He’s against the Iraq war (and has voted against it every time it’s come up in Congress), he’s for a national single-payer healthcare system, against warrantless wiretapping (voted against the Patriot Act every time it’s come up), and for an Energy Policy that moves us away from oil and coal.

That’s actually how I was leaning to vote in the primaries, so kudos to Glassbooth for accuracy.

One nice feature: the site gives you references for each of the policy positions they claim for the candidates.  I like reading what the candidate has *actually* said (or even better, how they’ve voted) about an issue, rather relying on some pundit’s assumption that so-and-so is “liberal” or “conservative.”

Try the survey out. What are your results?  Are they what you expected?  Do the results change how you will/would vote?

How To Install Ubuntu on a Mac Pro

I got my hands on a Mac Pro at work over the holiday, and the first thing I did was install Ubuntu Linux on it. Everything went smoothly using the new 7.10 version of Ubuntu, so I wanted to post how I did it:

[Note: I’m assuming below that you’re running OS 10.5 and have already run Software Update to make sure your Mac software is current]

1. Download the Ubuntu 7.10 64-bit install disk from here.

2. Burn the Ubuntu ISO to a CD.

3. Download and install rEFIt. (Do this in OS X). I had to use their manual install. Don’t worry, it’s not hard; you just have to copy a folder from one location to another, then enter two lines into a Terminal window.

4. Run BootCamp (It’s in your Applications -> Utilities directory). Use it to partition your Mac Pro’s hard drive to make room for Linux. You can set the partition sizes to whatever you want; I left 100 GB for my Mac OS and 140 GB for Ubuntu. When the partitioning is done, quit BootCamp. Don’t let it to do anything else.

5. Insert the Ubuntu CD you made into your Superdrive and reboot. rEFIt should pop up and let you choose to boot from the CD. Do that.

6. Choose the first option from the Ubuntu CD menu. When Ubuntu boots, play around with it for a while to make sure it sees your hardware properly. I have an ATI X1900 video card that Ubuntu found and worked with perfectly; I can’t vouch for Nvidia cards, so make sure you can set your screen resolution okay.

7. When you’re satisfied that Ubuntu can “see” your hardware okay, double-click the “Install Ubuntu” icon on the desktop.

8. Okay, now comes the one scary part. Follow the install wizard’s instructions until you get to the partitioner. Choose Manual. When you see a list of partitions, find the one you made using BootCamp (you can tell from its size) and delete it. Now create a new partition of type ext3 using the rest of your available hard drive space. Set the mount point to “/”. You’ll get some warning about not having a swap partition. Ignore it, you’ll be fine.

9. Click through the rest of the installer and let it chug away.

10. When it tells you to remove the CD and reboot, do what it says. rEFIt should come up again and see your Linux install. Select it, watch Ubuntu boot, and enjoy your new Linux system!

That seems like a lot of work, but really it’s mostly just clicking a few default options and watching the installers run.

If you run into problems, or just want more information, check out this blog on running Linux on the Mac Pro, or the thorough Gentoo Linux Wiki page, or this helpful post on the Apple Forums.