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!

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.

How To Connect to iDisk in Ubuntu

For those Mac users who have switched to, or are trying out, Ubuntu Linux, here’s how to connect to your iDisk:

Step One:  Go to Places -> Connect to Server (from the top panelbar)

Step Two: Set the Service Type to “WebDav”.

Step Three: Enter “” as the Server.

Step Four:  Enter your .Mac username in both the “Folder” and “Username” boxes.

Step Five: Hit “Connect”.  A folder should appear on your desktop called “”.  Double-click the folder, and enter your .Mac account password when prompted.

That’s it!  You can access your entire iDisk from that folder on your desktop.  When you’re done, just right-click on the folder and choose “Unmount Volume” to Disconnect.