Using BBEdit’s shell worksheet to rename files

BBedit’s shell worksheet can be a really handy tool for batch renaming files. I was inspired to give it a shot after seeing a script that handed off a directory listing for editing. Here’s a really trivial example. Let’s say I have a directory containing the following files (and I’ve cd‘d to it in the worksheet):


And let’s say those files are actually Markdown, so I want to change the extension to .md.

First, type ls and execute it with Control-Return to get the listing of those files in your worksheet window. The result looks like the example above.

Next, highlight the listing, and bring up the “Find” dialogue. Make sure that “Grep” and “Selected text only” are selected.

Enter the pattern (.*?)(\.txt), meaning a lazy search of any characters up to a literal .txt, broken into two tokens. The first token is the file name, the second token is the extension. You want to replace that with mv \1\2 \;. The result will look like this:

mv foo1.txt;
mv foo2.txt;
mv foo3.txt;

Select those lines and execute them using Control-Return. If you do another ls, you’ll see your files have been renamed.

This example is really simple, just to get you thinking about the kind of file renaming you can do. Remember that a shell worksheet in BBEdit is a regular editing window. Any snippets, scripts, or text factory you have set up are available to you.

Get f.lux on your iPhone jailbreak free

Via Jason Snell, the f.lux folks have documented the process of getting f.lux onto your iPhone without jailbreaking. The process is legitimate; it uses Xcode and the new provisions in the Apple developer program. It’s a bit complicated, so you may just chose to do what I do, and wear cheap sunglasses with yellow lenses.

(For why you would care about any of this, check out Blue light has a dark side at Harvard Health.)

An easier way to kill processes

I’ve moved on from ps aux | grep -i processname; kill PID. The Mac (along with many other Unix-likes) has two handy utilities: pgrep and pkill. pgrep does a case-insensitive search for processes matching the expression you provide, and returns all matching PIDs, one per line. pkill does the same search, but just kills the matching processes instead of returning the PIDs.

A common use case for me is middleman hanging when I change the config.rb. I could kill it using the following:

kill `pgrep middleman`

pkill middleman

One of the benefits of using pkill is that you can run the command interactively. Handy if you end up searching on the scripting language running the process, rather than something a bit more unique.