There's never enough time in the day to watch all those great TV shows you want to see. Turning your computer into a personal video recorder, or "PVR," has become all the rage. A Macintosh PVR can accomplish many things. At the most basic, it lets you time-shift your shows to watch them at a convenient hourwhen you're ready to watch, not when network executives think you should be watching.
In addition, you might record a show for a friend, and then ftp it over, or perhaps send it in segments through e-mail to a Gmail account. You could even let your Mac record all the great shows you think you should watch and then just trash the results. Even if you didn't see the show, your Mac did—and it probably enjoyed it more than you would have anyway. No matter why you want to use your Mac to record TV, HackTV (with a little help from iCal) provides a free and simple automatic video recording solution.
This is the second article in a series about watching TV with Apple's (free) HackTV utility. In the first article, I showed readers how to connect their TVs and other video sources to their Macintoshes using FireWire and watch it with HackTV. Then I discussed how to record that video to disk. This article continues from there.
You're about to learn how to convert your Macintosh to a low-end but working PVR. You'll discover how to control HackTV through Apple's GUI scripting extensions for AppleScript (at least as much as Mac OS X will let you) and how to schedule your recordings with iCal. After mastering the skills in this article, you'll be able to walk away from your Mac and let it handle any recording tasks for you.
In the best of all possible worlds, your Macintosh might wake itself up on a Tuesday evening after checking the latest updates of your local TV listings, reach out through an IR blaster attached to its USB port, tune your digital cable box to the local CBS affiliate, and automatically start recording "The Amazing Race," remembering to start and end the recording two minutes earlier than the listed times.
This article does not concern itself with the best of all possible worlds. It's about cheap and convenient hacks.
Keeping that in mind, you can only expect so much when using your HackTV setup to record video. Here are a few reminders.
Despite these caveats, it is possible to schedule and record with HackTV as you'll learn in this article.
Do you remember that great scene in Billy Crystal's "City Slickers" movie? During the long cattle drive, actors Crystal and Bruno Kirby attempt to explain to Daniel Stern's character exactly how one can watch one show on TV while recording another. HackTV is kind of like that. When making your connections to HackTV, you have to decide whether to watch the signal that's already playing on your TV or use a different tuner to record a second show.
If you receive satellite TV, the decision is more or less already made for you. Unless you want to fork out the money for a separate receiver, you'll need to hook HackTV to the extra output jacks on the back of the receiver box. (Satellite boxes almost always offer a second set of jacks.) What you watch on TV, you'll watch on HackTV.
If you subscribe to cable, you can be more flexible. Although digital cable boxes present the same problem as satellite TV—you need a second box to get a different signal—you can split standard cable signals at will and tune them separately. Signal splitters are available for very little money at most hardware stores. Many dollar stores even carry them.
To split your signal, use coaxial cable to connect your wall jack to the splitter and then to connect the splitter's output jacks to your TV and to your extra tuner. I highly recommend digging out an older VCR from storage (or from a local Goodwill store) to provide an extra tuner. Even broken VCRs work. They don't have to play VHS tapes properly to tune TV signals; these are entirely separate issues. As you'd expect, using a split signal with a second tuner lets you watch one show on TV and record a different show on HackTV.
An inexpensive cable splitter and a cheap VCR provide a great (and low-cost) solution
that allows you to watch one show on TV and record a different show to HackTV.
HackTV is, at best, barely scriptable. It's old. It's Carbon. It's not very compliant with the new OS X GUI scripting additions. You can make it start recording. You can make it stop recording. You can even tell it what file to record to. But you can't really automate the video settings—and believe me, I've tried. These limitations mean that HackTV must already be running with its video and sound options set before you start automatic recordings. (Note: Apple introduced GUI scripting in response to programmer demand for AppleScript control of applications that were not specifically written with AppleScript support. GUI scripting lets you programmatically generate interface events such as clicking buttons or selecting items from menus.)
Follow these steps to make sure that HackTV is ready for your recording.
After setting up HackTV, you'll need to prepare the AppleScript script that runs the recording. For this you'll use Apple's Script Editor application. In the following steps, you'll learn how to create and customize this script.
Launch Script Editor. A new Untitled window opens.
A typical Script Editor window Paste the following code into the top pane of the Untitled script editor, just under the toolbar. This script tells HackTV to record for a certain number of minutes that you specify.
-- ------------------------
-- Record via HackTV
-- ------------------------
-- Specify the recording duration
set howmanyminutes to 30
-- Set the recording name
set tw to words of ((current date) as string)
set rn to getName()
-- Part I: Activate HackTV and Start Recording.
tell application "HackTVCarbon"
activate
delay 4
tell application "System Events"
tell application process "HackTVCarbon"
click menu item "Record Without Hogging Machine" of menu "Monitor"
of menu bar item "Monitor" of menu bar 1
keystroke rn -- name to save as
click button "Save" of window "Save"
end tell
end tell
end tell
-- Pause for however many minutes of recording
delay howmanyminutes * 60
-- Part II: End the recording
tell application "HackTVCarbon"
activate
tell application "System Events"
tell application process "HackTVCarbon"
click menu item "Stop Recording" of menu "Monitor" of menu bar item
"Monitor" of menu bar 1
delay 2 -- wait for "finished" dialog to appear
keystroke return
end tell
end tell
end tell
-- Return a name for the file based on current date & time
on getName()
set datewords to words of ((current date) as string)
set rstring to (item ((month of (current date)) as integer) of {"Jan",
"Feb", "Mar", "Apr", "May", "Jun", "Jul", "Aug", "Sep", "Oct", "Nov", "Dec"})
set rstring to rstring & (((day of (current date)) as integer) as string)
set rstring to rstring & "-"
set rstring to rstring & item 5 of datewords & "." & item 6 of datewords &
item 8 of datewords & ".mov"
return rstring
end getName
Click the Compile button in the window's toolbar. The Script Editor compiles the code and updates the fonts to the multicolored result seen here.
The multicolored format (called "pretty printing") indicates that
the Script Editor has successfully compiled your AppleScript code.
Save your script to your desktop. With iCal, you can record TV at any time you want. iCal alarms make it possible. All you have to do is schedule an AppleScript by adding it to your calendar as a new event. Here's how.
Adding an iCal alarm lets you automatically run your HackTV script.
After adding this alarm to your event, you'll have instructed iCal to launch your script exactly at the time you specified. All you have to do now is sit back and wait—or even better, get up from your computer and go do something else. (Note: Make sure your System Preferences -> Energy Saver settings do not automatically put your computer to sleep. This will interfere with the recording.)
After your scheduled recording has finished, you'll find a new file on your desktop when you return to your computer. The file name, which is set in your script, is based on the day and time your recording took place. So if you set up your iCal event to repeat, each recording will bear a different name. To watch the recording, simply double-click the icon. QuickTime Player will launch and display the recorded video.
Your script tells HackTV to create a recording labeled with the date and time
of the recording. This article has shown how the one-two punch of HackTV and iCal can turn your Mac into a simple personal video recorder. Hardly elaborate, HackTV still gets the job done—and it does it for free. You've seen how to prepare your recording and set it in motion. If all has gone well and according to plan, your new recordings will be waiting for you on your desktop when you return.
Erica Sadun has written, co-written, and contributed to almost two dozen books about technology, particularly in the areas of programming, digital video, and digital photography.
Return to digitalmedia.oreilly.com
Copyright © 2007 O'Reilly Media, Inc.