Mike Bland

I Should Be Practicing

There are many better uses of my time than getting sucked into writing demented Python scripts for Mac OS X. That doesn't seem to matter, always.

- Boston
Tags: Mac OS X, programming, time sink

Somehow, via Isaac Truett’s repost of a Robert Konigsberg post that I just stumbled upon today, I thought it was worth my time to take Rob’s creepy one-line Mac OS X shell script to the next little level. See, when I ran the say -v ? command in that script, I found the output…amusing. But, since it’s a pain to parse strings into multiple fields in a shell loop, I dropped down to Python to do the dirty deed.

I call it creepy.py. Run it with the lights on, folks.

#! /usr/bin/env python

import os
import re
import subprocess

for l in subprocess.Popen(['say', '-v', '?'],
    stdout=subprocess.PIPE).communicate()[0].split('\n'):
  if not l: break
  l = re.sub('   +', '|', l)
  name, _, quote = [s.strip('# ') for s in l.split('|')]
  print "%s: %s" % (name, quote)
  subprocess.call('say -v "%s" "My name is %s. %s"' % (name, name, quote),
                  shell=True)