How the What I'm watching on TV Page Works.


About My Computer

Let me start off by saying that I have a PowerPC 8100/80AV. Yes it's a Macintosh for all you non-believers. Let me also say that any of you who have AV (Audio/Video) Macintoshes and an internet connection can create a page just like this one. It's not too difficult. If you understand this page, then you'll be able to do it in a matter of hours. The setup I have works best with a non-ethernet connection. . The great thing is that all of the software you need to accomplish the task is shareware. (Now you all pay those poor programmers, don't you!!!?)

A General Explanation

On the simplest level, this page is fairly straight forward. I capture a picture, change it's format and then download the picture to a server at Berkeley. Everything is done automatically every five minutes. I can just sit back and watch the computer work without having to do a thing. Since I only have dialup access at the moment. I can't keep the computer online all the time. That is why there are long periods when the page isn't working.

The Tools I'm Using To Make It Work

Right now I'm using four programs, plus an AppleScript to make the whole setup work. The program that does the meat of the work is called PhotoCapture . It's a scriptable frame grabber that captures pictures and saves them as pictures on my hard drive. It's a definite must if you're capturing stills from video.

I also use a Program called Clip2Gif which converts the picture from a PICT to a interlaced gif. Although changing the format from a pict that is thousands of colors to a lower quality gif does ruin the pictures slighty, gif's are a standard on the WWW that we're supposed to use.

I'm using Anarchie to download the picture to a server at Berkeley. Not only is it the best FTP program for the Macintosh, but it's also scriptable.

Finnally, I'm using the Scriptable Text Editor that comes with applescript to edit the html document. Why do I need to edit it? To put the current time on the page of course.

All of these programs are AppleScriptable. Although it would be possible to create this page without scriptable applications, it isn't wise. That's how this page ran for about a month before I realized how much better it was to use scriptable applications. Trust me on this one.

About Applescripts

Applescript is a powerful tool for Macintoshes that allows you to automate tasks and link many programs together. It is very useful and unlike most scripting languages, the scripts are almost in plain English. It's very easy to learn.

The Script

Here's the script I'm using. I no longer consider it a hack since I'm not using Autotyper and Video Monitor. Although it's not needed, you might want to get JonsCommand's if you're planning to use the script I have below. The script is here free for use, but I'd like to know if you're actually putting it to good use. If you setup a page based on this script, just send me the URL, I'd like to see it. To see how my computer is configured, you can look here. It's a page similar to this one which explains how I'm actually capturing pictures.

property mytaken : false --Property to make sure that a picture is not taken twice in a minute.
property pictureNumber : 1
--Tell me if I'm taking picture one or two, this is needed to alternate between pictures
--on the page. A value of 1 means Picture 1 and -1 means Picture 2. I multipy it by -1
--everytime I take a picture to alternate between the two.


on idle --When the computer is not busy
	if ((((characters 4 thru 6 of (the time string of (current date))) as string) contains "0:") or (((characters 4 thru 6 of (the time string of (current date))) as string) contains "5:") and mytaken is equal to false) then
		--If the time has a zero or a five in the minutes column.
		set mytaken to true
		tell application "PhotoCapture"
			Capture to File "Hard Disk 1030:Desktop Folder:current.pict" --Save it to where you want to save it.
			--Notice that I don't quit or activate PhotoCapture. It's always open to save time and to allow me
			--to watch TV when I'm running the page. If you don't want to have the overhead of running another
			--program then add the activate and quit lines.
		end tell
		ConvertToGif()
		--I use this sub procedure to get around a File not Found error that sometimes occurs.
		--The problem is that it sometimes takes a while for current.pict to show up on the desktop
		--If Clip2Gif tries to convert a file that doesn't yet exist then it will return an error.
		--Look at the bottom of the page to see how it works, I know that it's making recursive calls
		--To itself until it can convert the picture. You might think that this is dangerous, but there's
		--Never really a problem with it
		copy (the time string of (current date)) to theTime --Get the current time.
		tell application "Scriptable Text Editor" --Again notice that I'm not telling it to activate. I wan it to run in the background
			open file "Hard Disk 1030:Desktop Folder:html Docs:sunset.html" --Open the html doc to change the current time
			select text from word 207 to word 210 of document 1 --Change the old time, this changes depending on the HTML doc.
			set selection to theTime
			save document 1 in file "Hard Disk 1030:Desktop Folder:html Docs:sunset.html"
			close document 1 saving no
			--open file "Hard Disk 1030:Desktop Folder:html Docs:ncaanoback.html"
			--select text from word 250 to word 253 of document 1
			--set selection to theTime
			--save document 1 in file "Hard Disk 1030:Desktop Folder:html Docs:ncaanoback.html"
			--close document 1 saving no
			quit
		end tell
		set pictureNumber to (pictureNumber * -1)
		tell application "Anarchie" --download the file to a server at school, password deleted for security reasons.
			try
				if pictureNumber is equal to 1 then
					store file "Hard Disk 1030:Desktop Folder:current.gif" host "csua.berkeley.edu" path "/www/m/milesm/public_html/tv.gif" user "milesm" password "DELETED"
				else
					store file "Hard Disk 1030:Desktop Folder:current.gif" host "csua.berkeley.edu" path "/www/m/milesm/public_html/tv1.gif" user "milesm" password "DELETED"
				end if
				store file "Hard Disk 1030:Desktop Folder:html docs:sunset.html" host "csua.berkeley.edu" path "/www/m/milesm/public_html/ontv.html" user "milesm" password "DELETED"
				store file "Hard Disk 1030:Desktop Folder:html docs:sunset.html" host "csua.berkeley.edu" path "/www/m/milesm/public_html/ontvnb.html" user "milesm" password "DELETED"
				quit
			on error
			end try
		end tell
		
	else --We're in a minute where we're not taking a picuture.
		set mytaken to false --reset the variable mytaken in minutes where we are not taking a picture
		tell application "Finder"
			try
				deleteFile "Hard Disk 1030:Desktop Folder:current.pict"
				deleteFile "Hard Disk 1030:Desktop Folder:current.gif"
				-- Delete the old files. I use Jon's Commands for this because it is faster.
				-- You could also use delete file "Filepath" if you have a scriptable finder and you don't want to
				-- use Jon's Commands.
			on error
				--Do nothing, the file doesn't exist so we don't need to do anything.
			end try
			-- If one of the files doesn't exist don't do anything. This implemntation is faster than testing
			--to see if the file exits. As you can see, I don't have to test anything, and time is essential.
			--I'm also doing this in the dead time when we're not taking a picture to save time.
		end tell
	end if
end idle

on ConvertToGif()
	tell application "clip2gif"
		try
			--Try to convert the picture. If unable then it may be possible that current.gif wasn't deleted or
			--That current.pict hasn't showed up yet. In the first case delete current.gif, in the second keep
			--trying to convert current.pict until it shows up. We just took it with photocapture so it must exist. 
			convert "Hard Disk 1030:Desktop Folder:current.pict" saving as GIF in file "Hard Disk 1030:Desktop Folder:current.gif"
		on error
			try
				deleteFile "Hard Disk 1030:Desktop Folder:current.gif"
			on error
			end try
			ConvertToGif()
		end try
		quit
	end tell
end ConvertToGif
 
>