Multi-file find & replace over SFTP

I recently heard from Koklynn (via Nelson) that Google Analytics had changed their tracking code. I like to keep things up to date, so I started the process of replacing the old code with the new. It took about 10 seconds to update the template on my WordPress-powered blog, but I also have a bunch of static HTML files sitting around from my old site.

Usually when I want to do a multi-file find and replace, I just fire up TextWrangler and go at it. However, I only knew how to specify the folder to search if I could access it from the Finder. I didn’t want to download, edit, and then re-upload all of my files, and the current Finder won’t mount volumes over SFTP. Smart people can probably just SSH into their accounts and type a few lines to do what I wanted, but I’m not smart. I needed to find a way to use a GUI to find and replace over a bunch of HTML files via SFTP.

I quickly discovered that TextWrangler can open files via SFTP, but I couldn’t figure out how to specify the path to search in the multi-file search. I also tried dragging the folder I wanted over from Cyberduck, but that didn’t work either. I needed to get these files from the Finder. I then remembered that Matt had been using macFUSE to do FTP uploads from the Finder. I hadn’t really read up on macFUSE, but it sounded like something could would work for me. So I went ahead and installed the core package, and then found MacFusion, which gave me a nice GUI, allowing me to quickly mount my server account in the Finder. (See update at bottom of post.) I went ahead and dragged the public_html folder to the sidebar, so I was able to quickly locate it in the Find/Replace window of TextWrangler after clicking on Other:

Find/Replace dialog of TextWrangler

I also set up a filter so TextWrangler would only check the HTML files, by clicking on Options and then Edit Filter.

After that, I just sat back and let it go:

find/replace status window

I think I got everything converted to the new code, but if you find any of the old stuff lying around go ahead and let me know.

But wait! This post isn’t over yet; I have three more Mac geek-related things:

1: This is my first post with WordPress 2.5 using images. This is notable, because when I first tried the image uploader, I got an HTTP error. After some searching, I learned that this is caused by a problem with the Mac version of Flash. A variety of solutions were proposed, but it looked like they all involved either installing a plugin or disabling a security feature, two things I don’t like to do without good reason. Then, I noticed on the WordPress bug filed for the issue that the fix was simply to disable the Flash uploader for Macs if the mod_security module is enabled. This fix isn’t in the current release of WordPress, but it was easy enough for me to create the same effect without modifying any source code. I just went into Safari’s preferences, opened the Security tab, and unchecked Enable plug-ins. That disabled Flash, and I was able to use the alternate uploader with no problem.

2. Speaking of images, it’s nice that when I do a ⌘-Shift-4-Space capture of a window it includes the drop shadow, but I’d also like the option to not capture the shadow without having to manually select the window using the crosshairs or opening Grab or another utility.

3. I like that I can use the familiar Mac-standard ⌘I and ⌘B keyboard shortcuts in the WordPress 2.5 visual editor. I don’t think this worked in earlier versions.

Update: As I was closing out my windows for the day I realized that MacFusion, although cool, was unnecessary. I had already mounted my account on the desktop successfully via sshfs.

One thought on “Multi-file find & replace over SFTP”

  1. yet another reason to template your site…i made the same update about a month ago…took me about 5 seconds.

    granted, I only have about 5 non-Wordpress pages…but even if I had 5,000 is still would have taken me 5 seconds.

    2. I agree about the drop shadow thing. One of the reasons why I just use Grab by default now (also because I refuse to memorize any keystroke combination longer than 3 keys).

Leave a Reply

Your email address will not be published. Required fields are marked *