Group Project: Mac for the Blind!!

I was sitting here thinking after seeing MacDictate, it’s kind of unfair that a program like that costs so much because it could help the blind operate Macs. So I thought I would start a group project to make a guide dog for the Mac OS that would be free for them. Maybe even call it “GuideDog”.

Here’s a script I started:


--Guide Dog
tell application "SpeechRecognitionServer"
	listen continuously for {"Open Finder", "Open System Preferences", "Open iTunes", "Open Safari", "Open Mail", "Open iPhoto", "Open Pages", "Open Numbers", "Open Keynote", "Open Address Book", "Open iCal", "Open iChat", "Open Photo Booth", "Open TextEdit", "Open Preview"}
	
--Finder
	if the result is "Open Finder" then
		tell application "Finder"
			activate
			say "Finder" using "Alex"
			tell application "SpeechRecognitionServer"
				listen continuously for {"Open Finder", "New Finder Window", "New Folder", "Empty Trash", "Arrange By", "Computer Sleep", "Computer Restart", "Computer Shut Down"}
				if the result is "Open Finder" then
					tell application "Finder"
						activate
						say "Finder" using "Alex"
					end tell
				else if the result is "New Finder Window" then
					tell application "Finder"
						make new Finder window
						say "New Finder Window" using "Alex"
					end tell
				else if the result is "New Folder" then
					tell application "Finder"
						make new folder
						say "New Folder" using "Alex"
					end tell
				else if the result is "Empty Trash" then
					tell application "Finder"
						empty trash
						say "Taking out the Garbage" using "Alex"
					end tell
					
				else if the result is "Arrange By" then
					say "Arrange By What?" using "Alex"
					tell application "SpeechRecognitionServer"
						listen continuously for {"Name", "Date Modified", "Date Created", "Size", "Kind", "Label"}
						if the result is "Name" then
							tell application "Finder"
								activate
								tell application "System Events"
									click menu item "Name" of menu "Arrange By" of menu item "Arrange By" of menu "View" of menu bar 1 of process "Finder"
								end tell
							end tell
						else if the result is "Date Modified" then
							tell application "Finder"
								activate
								tell application "System Events"
									click menu item "Date Modified" of menu "Arrange By" of menu item "Arrange By" of menu "View" of menu bar 1 of process "Finder"
								end tell
							end tell
						else if the result is "Date Created" then
							tell application "Finder"
								activate
								tell application "System Events"
									click menu item "Date Created" of menu "Arrange By" of menu item "Arrange By" of menu "View" of menu bar 1 of process "Finder"
								end tell
							end tell
						else if the result is "Size" then
							tell application "Finder"
								activate
								tell application "System Events"
									click menu item "Size" of menu "Arrange By" of menu item "Arrange By" of menu "View" of menu bar 1 of process "Finder"
								end tell
							end tell
						else if the result is "Kind" then
							tell application "Finder"
								activate
								tell application "System Events"
									click menu item "Kind" of menu "Arrange By" of menu item "Arrange By" of menu "View" of menu bar 1 of process "Finder"
								end tell
							end tell
						else if the result is "Label" then
							tell application "Finder"
								activate
								tell application "System Events"
									click menu item "Label" of menu "Arrange By" of menu item "Arrange By" of menu "View" of menu bar 1 of process "Finder"
								end tell
							end tell
						end if
					end tell
					
				else if the result is "Computer Sleep" then
					tell application "Finder"
						say "Goodnight" using "Alex"
						sleep
					end tell
				else if the result is "Computer Restart" then
					tell application "Finder"
						say "Restarting Computer"
						restart
					end tell
				else if the result is "Computer Shut Down" then
					tell application "Finder"
						say "Computer Shutting Down" using "Alex"
						shut down
					end tell
				end if
			end tell
		end tell
		
		
--System Preferences
	else if the result is "Open System Preferences" then
		tell application "System Preferences"
			activate
			say "System Preferences" using "Alex"
			tell application "SpeechRecognitionServer"
				listen continuously for {"Open System Preferences", "Close System Preferences"}
				if the result is "Open System Preferences" then
					tell application "System Preferences"
						activate
						say "System Preferences" using "Alex"
					end tell
				else if the result is "Close System Preferences" then
					tell application "System Preferences"
						say "Closing System Preferences"
						quit
					end tell
				end if
			end tell
		end tell
		
--iTunes
	else if the result is "Open iTunes" then
		tell application "iTunes"
			activate
			say "iTunes" using "Alex"
			tell application "SpeechRecognitionServer"
				listen continuously for {"Open iTunes", "Play", "Pause", "Stop", "Next Track", "Back Track", "Mute", "Close iTunes"}
				if the result is "Open iTunes" then
					tell application "iTunes"
						activate
						say "iTunes" using "Alex"
					end tell
				else if the result is "Play" then
					tell application "iTunes"
						play
					end tell
				else if the result is "Pause" then
					tell application "iTunes"
						pause
					end tell
				else if the result is "Stop" then
					tell application "iTunes"
						stop
					end tell
				else if the result is "Next Track" then
					tell application "iTunes"
						next track
					end tell
				else if the result is "Back Track" then
					tell application "iTunes"
						back track
					end tell
				else if the result is "Mute" then
					tell application "iTunes"
						set volume 0
					end tell
				else if the result is "Close iTunes" then
					say "Closing iTunes" using "Alex"
					tell application "iTunes"
						quit
					end tell
				end if
			end tell
		end tell
		
--Safari
	else if the result is "Open Safari" then
		tell application "Safari"
			activate
			say "Safari" using "Alex"
			tell application "SpeechRecognitionServer"
				listen continuously for {"Open Safari", "Go To", "Close Safari"}
				if the result is "Open Safari" then
					tell application "Safari"
						activate
						say "Safari" using "Alex"
					end tell
					
				else if the result is "Go To" then
					tell application "SpeechRecognitionServer"
						say "What Website?" using "Alex"
						listen continuously for {"Google", "Apple", "MacScripter", "Yahoo"}
						if the result is "Google" then
							tell application "Safari"
								activate
								open location "http://www.google.com/"
								say "Google" using "Alex"
							end tell
						else if the result is "Apple" then
							tell application "Safari"
								activate
								open location "http://www.apple.com/"
								say "Apple" using "Alex"
							end tell
						else if the result is "MacScripter" then
							tell application "Safari"
								activate
								open location "http://macscripter.net/index.php"
								say "MacScripter" using "Alex"
							end tell
						else if the result is "Yahoo" then
							tell application "Safari"
								activate
								open location "http://m.www.yahoo.com/"
								say "Yahoo" using "Alex"
							end tell
						end if
					end tell
					
				else if the result is "Close Safari" then
					tell application "Safari"
						say "Closing Safari" using "Alex"
						quit
					end tell
				end if
			end tell
		end tell
		
--Mail
	else if the result is "Open Mail" then
		tell application "Mail"
			activate
			say "Mail" using "Alex"
			tell application "SpeechRecognitionServer"
				listen continuously for {"Open Mail", "Close Mail"}
				if the result is "Open Mail" then
					tell application "Mail"
						activate
						say "Mail" using "Alex"
					end tell
				else if the result is "Close Mail" then
					tell application "Mail"
						say "Closing Mail"
						quit
					end tell
				end if
			end tell
		end tell
		
--iPhoto
	else if the result is "Open iPhoto" then
		tell application "iPhoto"
			activate
			say "iPhoto" using "Alex"
			tell application "SpeechRecognitionServer"
				listen continuously for {"Open iPhoto", "New Album", "Empty Trash", "Close iPhoto"}
				if the result is "Open iPhoto" then
					tell application "iPhoto"
						activate
						say "iPhoto" using "Alex"
					end tell
				else if the result is "New Album" then
					tell application "iPhoto"
						new album
						say "New Album" using "Alex"
					end tell
				else if the result is "Empty Trash" then
					tell application "iPhoto"
						say "Removing Photos from the Trash" using "Alex"
						empty trash
					end tell
				else if the result is "Close iPhoto" then
					tell application "iPhoto"
						say "Closing iPhoto"
						quit
					end tell
				end if
			end tell
		end tell
		
--Pages
	else if the result is "Open Pages" then
		tell application "Pages"
			activate
			tell application "System Events"
				click button "Choose" of window "Template Chooser" of process "Pages"
			end tell
			say "Pages" using "Alex"
			tell application "SpeechRecognitionServer"
				listen continuously for {"Open Pages", "New Document", "Save", "Select All", "Close Pages"}
				if the result is "Open Pages" then
					tell application "Pages"
						activate
						tell application "System Events"
							click button "Choose" of window "Template Chooser" of process "Pages"
						end tell
						say "Pages" using "Alex"
					end tell
				else if the result is "Save" then
					tell application "Pages"
						activate
						tell application "System Events"
							click menu item "New" of menu "File" of menu bar 1 of process "Pages"
						end tell
						say "Saved Document" using "Alex"
					end tell
				else if the result is "Select All" then
					tell application "System Events"
						click menu item "Select All" of menu "Edit" of menu bar 1 of process "Pages"
						say "All Selected" using "Alex"
					end tell
				else if the result is "New Document" then
					tell application "Pages"
						activate
						tell application "System Events"
							click menu item "New" of menu "File" of menu bar 1 of process "Pages"
							click button "Choose" of window "Template Chooser" of process "Pages"
						end tell
						say "New Pages Document" using "Alex"
					end tell
				else if the result is "Close Pages" then
					tell application "Pages"
						say "Closing Pages"
						quit
					end tell
				end if
			end tell
		end tell
		
--Numbers
	else if the result is "Open Numbers" then
		tell application "Numbers"
			activate
			say "Numbers" using "Alex"
			tell application "SpeechRecognitionServer"
				listen continuously for {"Open Numbers", "Close Numbers"}
				if the result is "Open Numbers" then
					tell application "Numbers"
						activate
						say "Numbers" using "Alex"
					end tell
				else if the result is "Close Numbers" then
					tell application "Numbers"
						say "Closing Numbers"
						quit
					end tell
				end if
			end tell
		end tell
		
--Keynote
	else if the result is "Open Keynote" then
		tell application "Keynote"
			activate
			say "Keynote" using "Alex"
			tell application "SpeechRecognitionServer"
				listen continuously for {"Open Keynote", "Close Keynote"}
				if the result is "Open Keynote" then
					tell application "Keynote"
						activate
						say "Keynote" using "Alex"
					end tell
				else if the result is "Close Keynote" then
					tell application "Keynote"
						say "Closing Keynote"
						quit
					end tell
				end if
			end tell
		end tell
		
--Address Book
	else if the result is "Open Address Book" then
		tell application "Address Book"
			activate
			say "Address Book" using "Alex"
			tell application "SpeechRecognitionServer"
				listen continuously for {"Open Address Book", "Close Address Book"}
				if the result is "Open Address Book" then
					tell application "Address Book"
						activate
						say "Address Book" using "Alex"
					end tell
				else if the result is "Close Address Book" then
					tell application "Address Book"
						say "Closing Address Book"
						quit
					end tell
				end if
			end tell
		end tell
		
--iCal
	else if the result is "Open iCal" then
		tell application "iCal"
			activate
			say "iCal" using "Alex"
			tell application "SpeechRecognitionServer"
				listen continuously for {"Open iCal", "Close iCal"}
				if the result is "Open iCal" then
					tell application "iCal"
						activate
						say "iCal" using "Alex"
					end tell
				else if the result is "Close iCal" then
					tell application "iCal"
						say "Closing iCal"
						quit
					end tell
				end if
			end tell
		end tell
		
--iChat
	else if the result is "Open iChat" then
		tell application "iChat"
			activate
			set status to available
			say "iChat" using "Alex"
			tell application "SpeechRecognitionServer"
				listen continuously for {"Open iChat", "Close iChat"}
				if the result is "Open iChat" then
					tell application "iChat"
						activate
						set status to available
						say "iChat" using "Alex"
					end tell
				else if the result is "Close iChat" then
					tell application "iChat"
						say "Closing iChat"
						quit
					end tell
				end if
			end tell
		end tell
		
--Photo Booth
	else if the result is "Open Photo Booth" then
		tell application "Photo Booth"
			activate
			say "Photo Booth" using "Alex"
			tell application "SpeechRecognitionServer"
				listen continuously for {"Open Photo Booth", "Close Photo Booth"}
				if the result is "Open Photo Booth" then
					tell application "Photo Booth"
						activate
						say "Photo Booth" using "Alex"
					end tell
				else if the result is "Close Photo Booth" then
					tell application "Photo Booth"
						say "Closing Photo Booth"
						quit
					end tell
				end if
			end tell
		end tell
		
--TextEdit
	else if the result is "Open TextEdit" then
		tell application "TextEdit"
			activate
			say "TextEdit" using "Alex"
			tell application "SpeechRecognitionServer"
				listen continuously for {"Open TextEdit", "Close TextEdit"}
				if the result is "Open TextEdit" then
					tell application "TextEdit"
						activate
						say "TextEdit" using "Alex"
					end tell
				else if the result is "Close TextEdit" then
					tell application "TextEdit"
						say "Closing TextEdit"
						quit
					end tell
				end if
			end tell
		end tell
		
--Preview
	else if the result is "Open Preview" then
		tell application "Preview"
			activate
			say "Preview" using "Alex"
			tell application "SpeechRecognitionServer"
				listen continuously for {"Open Preview", "Close Preview"}
				if the result is "Open Preview" then
					tell application "Preview"
						activate
						say "Preview" using "Alex"
					end tell
				else if the result is "Close Preview" then
					tell application "Preview"
						say "Closing Preview"
						quit
					end tell
				end if
			end tell
		end tell
		
	end if
end tell

Model: iMac
AppleScript: 2.3 (118)
Browser: Safari 531.22.7
Operating System: Mac OS X (10.6)

Hmm, it seems like your script repeats in some areas. You could use handlers to really simplify it.