Iron Man Script is here!

hey people, i just finished with a script that does the same thing as jarvas in the movie Iron Man, the only real difference is the voice synthesizing, so it doesn’t sound like him, but it uses the system voice on your computer. There are some minor, differences to, like the fact that it opens up thunderbird, and itunes plays music from a playlist - in this case “Skillet” (favorite band). You might want to edit it alittle to fit what you want. If there is any updates to this script, please post here or contact me some how. It totals to about 92 Kb

any way here is the script:


(*This script is copyright by Curtranhome - All Rights Reserved - Complete Access to this script is for everyone, but will need to present the script to Curtranhome*)
tell application "iTunes"
	activate
	play the playlist ("Skillet")
end tell

set volume 6

delay (10)
set weatherurl to "http://weather.yahoo.com/"
set city to "Sacramento CA"

tell application "Safari"
	activate
	make new document with properties {URL:weatherurl}
	repeat
		set docstate to (do JavaScript "document.readyState" in document 1)
		if docstate is "complete" then
			exit repeat
		end if
	end repeat
	delay 5
	do JavaScript "document.forms[2].elements[0].value = \"" & city & "\"" in document 1
	do JavaScript "document.forms[2].elements[1].click()" in document 1
	delay 5
	set websitesource to source of document 1
	close document 1
	set todayoffset to offset of "<strong>Today:</strong>" in websitesource
	set partwebsitesource to (characters todayoffset through -1 of websitesource) as text
	set listoffset to offset of "F" in partwebsitesource
	set todayweather to (characters 26 through (listoffset - 1) of partwebsitesource) as text
end tell

tell application "Thunderbird" to activate

delay (10)

(*Resize windows of iTunes, Safari and Thunderbird*)
tell application "Finder"
	set screen_resolution to bounds of window of desktop
	set screen_width to item 3 of screen_resolution
	set screen_height to item 4 of screen_resolution
end tell


set desired_width to 1000

set side_space to screen_width - desired_width
set left_bound to (side_space / 2)
set right_bound to left_bound + desired_width
set bottom_bound to screen_height
set top_bound to 22 (* for the menu bar *)

try
	tell application "iTunes"
		activate
		set the bounds of the first window to {left_bound, top_bound, right_bound, bottom_bound}
	end tell
end try

try
	tell application "Thunderbird"
		activate
		set the bounds of the first window to {left_bound, top_bound, right_bound, bottom_bound}
	end tell
end try

delay (5)

(*Say the Date*)
set myDate to get (current date)
set myMonth to get month of (current date)
set myDay to get day of (current date)
set myYear to get year of (current date)

if myDay is 1 then
	say ("Today is: " & myMonth & " 1st - " & myYear & "!")
else if myDay is 2 then
	say ("Today is: " & myMonth & " 2nd - " & myYear & "!")
else if myDay is 3 then
	say ("Today is: " & myMonth & " 3rd - " & myYear & "!")
else if myDay is greater than 3 then
	say ("Today is: " & myMonth & "  " & myDay & "th- " & myYear & "! ")
else if myDay is 31 then
	say ("Today is: " & myMonth & " 31st " & myYear & "!")
else if myDay is 21 then
	say ("Today is: " & myMonth & " 21st " & myYear & "!")
else if myDay is 22 then
	say ("Today is: " & myMonth & " 22nd " & myYear & "!")
else if myDay is 23 then
	say ("Today is: " & myMonth & " 23rd " & myYear & "!")
else
	say ("There is something wrong with the date applescript")
end if

(*say the current weather - scripted above*)
tell me
	say "and the weather is: " & todayweather & " degrees"
end tell

(*say the current time*)
set myHour to get hours of (current date)
set myMinute to get minutes of (current date)

if myHour is 1 then
	say ("it is now one-" & myMinute & " -A-M!")
else if myHour is 2 then
	say ("it is now two-" & myMinute & " -A-M!")
else if myHour is 3 then
	say ("it is now three-" & myMinute & " -A-M!")
else if myHour is 4 then
	say ("it is now four-" & myMinute & " -A-M!")
else if myHour is 5 then
	say ("it is now five-" & myMinute & " -A-M!")
else if myHour is 6 then
	say ("it is now six-" & myMinute & " -A-M!")
else if myHour is 7 then
	say ("it is now seven-" & myMinute & " -A-M!")
else if myHour is 8 then
	say ("it is now eight-" & myMinute & " -A-M!")
else if myHour is 9 then
	say ("it is now nine-" & myMinute & " -A-M!")
else if myHour is 10 then
	say ("it is now ten-" & myMinute & " -A-M!")
else if myHour is 11 then
	say ("it is now eleven-" & myMinute & " -A-M!")
else if myHour is 12 then
	say ("it is now twelve-" & myMinute & " -PM!")
else if myHour is 13 then
	say ("it is now one-" & myMinute & "-PM!")
else if myHour is 14 then
	say ("it is now two-" & myMinute & "-PM!")
else if myHour is 15 then
	say ("it is now three-" & myMinute & "-PM!")
else if myHour is 16 then
	say ("it is now four-" & myMinute & "-PM!")
else if myHour is 17 then
	say ("it is now five-" & myMinute & "-PM!")
else if myHour is 18 then
	say ("it is now six-" & myMinute & "-PM!")
else if myHour is 19 then
	say ("it is now seven-" & myMinute & "-PM!")
else if myHour is 20 then
	say ("it is now eight-" & myMinute & "-PM!")
else if myHour is 21 then
	say ("it is now nine-" & myMinute & "-PM!")
else if myHour is 22 then
	say ("it is now ten-" & myMinute & "-PM!")
else if myHour is 23 then
	say ("it is now eleven-" & myMinute & "-PM!")
else if myHour is 0 then
	say ("it is now twelve-" & myMinute & "-A-M!")
else
	say ("Error: there is something wrong with the time applescript number one.")
end if

delay (600)

(* Quit Thunderbird/Mail *)
say "Thunderbird will now quit"
tell application "Thunderbird" to quit

(*say the time after everything is done*)
set myHour to get hours of (current date)
set myMinute to get minutes of (current date)

if myHour is 1 then
	say ("it is now one-" & myMinute & " -A-M!")
else if myHour is 2 then
	say ("it is now two-" & myMinute & " -A-M!")
else if myHour is 3 then
	say ("it is now three-" & myMinute & " -A-M!")
else if myHour is 4 then
	say ("it is now four-" & myMinute & " -A-M!")
else if myHour is 5 then
	say ("it is now five-" & myMinute & " -A-M!")
else if myHour is 6 then
	say ("it is now six-" & myMinute & " -A-M!")
else if myHour is 7 then
	say ("it is now seven-" & myMinute & " -A-M!")
else if myHour is 8 then
	say ("it is now eight-" & myMinute & " -A-M!")
else if myHour is 9 then
	say ("it is now nine-" & myMinute & " -A-M!")
else if myHour is 10 then
	say ("it is now ten-" & myMinute & " -A-M!")
else if myHour is 11 then
	say ("it is now eleven-" & myMinute & " -A-M!")
else if myHour is 12 then
	say ("it is now twelve-" & myMinute & " -PM!")
else if myHour is 13 then
	say ("it is now one-" & myMinute & "-PM!")
else if myHour is 14 then
	say ("it is now two-" & myMinute & "-PM!")
else if myHour is 15 then
	say ("it is now three-" & myMinute & "-PM!")
else if myHour is 16 then
	say ("it is now four-" & myMinute & "-PM!")
else if myHour is 17 then
	say ("it is now five-" & myMinute & "-PM!")
else if myHour is 18 then
	say ("it is now six-" & myMinute & "-PM!")
else if myHour is 19 then
	say ("it is now seven-" & myMinute & "-PM!")
else if myHour is 20 then
	say ("it is now eight-" & myMinute & "-PM!")
else if myHour is 21 then
	say ("it is now nine-" & myMinute & "-PM!")
else if myHour is 22 then
	say ("it is now ten-" & myMinute & "-PM!")
else if myHour is 23 then
	say ("it is now eleven-" & myMinute & "-PM!")
else if myHour is 0 then
	say ("it is now twelve-" & myMinute & "-A-M!")
else
	say ("Error: there is something wrong with the time applescript number 2.")
end if

(*End of Script*)

Model: Power Mac
Browser: Safari 531.9
Operating System: Mac OS X (10.4)

Nice going, Curtranhome! I wrote something similar years ago when I was playing with the speech tools. I did notice a couple of areas that could be shortened. The “say date” section can be reduced to only 4 cases:

(1st/21st/31st, 2nd/22nd/32nd, 3rd/23rd/33rd, and nth)

and you can also shorten the “say time” section by realizing that the hour values > 12 can be fixed by subtracting 12 and creating a new variable to hold “am” or “pm”. Since you’re saying the time twice, you can also make that section a handler so you can just write it once and call it from the main script.

See what you think of this:


(*This script is copyright by Curtranhome - All Rights Reserved - Complete Access to this script is for everyone, but will need to present the script to Curtranhome*)
tell application "iTunes"
	activate
	play the playlist ("Skillet")
end tell

set volume 6

delay (10)
set weatherurl to "http://weather.yahoo.com/"
set city to "Sacramento CA"

tell application "Safari"
	activate
	make new document with properties {URL:weatherurl}
	repeat
		set docstate to (do JavaScript "document.readyState" in document 1)
		if docstate is "complete" then
			exit repeat
		end if
	end repeat
	delay 5
	do JavaScript "document.forms[2].elements[0].value = \"" & city & "\"" in document 1
	do JavaScript "document.forms[2].elements[1].click()" in document 1
	delay 5
	set websitesource to source of document 1
	close document 1
	set todayoffset to offset of "<strong>Today:</strong>" in websitesource
	set partwebsitesource to (characters todayoffset through -1 of websitesource) as text
	set listoffset to offset of "F" in partwebsitesource
	set todayweather to (characters 26 through (listoffset - 1) of partwebsitesource) as text
end tell

tell application "Thunderbird" to activate

delay (10)

(*Resize windows of iTunes, Safari and Thunderbird*)
tell application "Finder"
	set screen_resolution to bounds of window of desktop
	set screen_width to item 3 of screen_resolution
	set screen_height to item 4 of screen_resolution
end tell


set desired_width to 1000

set side_space to screen_width - desired_width
set left_bound to (side_space / 2)
set right_bound to left_bound + desired_width
set bottom_bound to screen_height
set top_bound to 22 (* for the menu bar *)

try
	tell application "iTunes"
		activate
		set the bounds of the first window to {left_bound, top_bound, right_bound, bottom_bound}
	end tell
end try

try
	tell application "Thunderbird"
		activate
		set the bounds of the first window to {left_bound, top_bound, right_bound, bottom_bound}
	end tell
end try

delay (5)

(*Say the Date*)
set myDate to get (current date)
set myMonth to get month of (current date)
set myDay to get day of (current date)
set myYear to get year of (current date)

if last character of myDay as text is "1" then
	set myDay to myDay & "st"
else if last character of (myDay as text) is "2" then
	set myDay to myDay & "nd"
else if last character of (myDay as text) is "3" then
	set myDay to myDay & "rd"
else
	set myDay to myDay & "th"
end if

say ("Today is: " & myMonth & space & myDay & space & myYear & "!")

(*say the current weather - scripted above*)
tell me
	say "and the weather is: " & todayweather & " degrees"
end tell

(*say the current time*)
sayTime()

delay (600)

(* Quit Thunderbird/Mail *)
say "Thunderbird will now quit"
tell application "Thunderbird" to quit

(*say the time after everything is done*)
sayTime()

(*End of Script*)

on sayTime()
	set myHour to get hours of (current date)
	set myMinute to get minutes of (current date)
	
	if myHour > 12 then
		set myHour to (my hour) - 12
		set ampm to "PM"
	else
		set ampm to "AM"
	end if
	say "it is now " & myHour & ":" & myMinute & space & ampm
end sayTime

Actually, you probably only need one case: nth (say does the right thing with “1th”, “2th”, and “3th”).

say "1th" --> "first"
say "2th" --> "second"
say "3th" --> "third"
say "21th" --> "twenty first"
say "22th" --> "twenty second"
say "23th" --> "twenty third"
say "31th" --> "thirty first"

Credit: Michelle Steiner on AppleScript-Users

Wow. I didn’t know that. I wonder if that’s something that we can count on not to change, or if some genius will “fix” it in a future release of AS.

Ok, thanks for your replies - they have really been helpful. But the only thing I need to work on is getting the voice to actually sound like/similar to iron man’s computer voice (can’t spell it’s name… lol). If you have any suggestions or ideas on this, then we can really start to revolutionize even faster.

Thanks again,
curtranhome

I believe his computer’s name is “Jarvis.” Don’t remember what he sounds like, but the Alex voice is the best male voice in the Speech preferences. The best female voice is Vicki (which came from Victoria, which was the best for a long time).

Check out Cepstral voices. They are not free but may have what you are looking for.

I get this error when I use this script: (Sorry for the enormous quote) Is this a Snow Leopard issue?

Try changing the line:

set websitesource to source of document 1

to

set websitesource to (source of document 1) as text

See if that fixes it.

A few changes I found I needed to make were the following:

Changed

do JavaScript "document.forms[2].elements[1].click()" in document 1

to

do JavaScript "document.forms[2].submit()" in document 1

for the “go” (page submit) button to be clicked without dealing with the button object itself

the second “change” is a bit more tricky (This is the source of your HUGE error text throw nBattle…)

in the following line the “Today” needs to change to “Tonight” after a certain point, because it does in the source code for the webpage

 set todayoffset to offset of "<strong>Today:</strong>" in websitesource

I put a try…on error to switch from Today to Tonight to have the script run correctly. See full script below.

Also changed this

set todayweather to (characters 26 through (listoffset - 1) of partwebsitesource) as text

to

set todayweather to (characters 28 through (listoffset - 1) of partwebsitesource) as text

to account for a leading “/n” that is now picked up in the forecast

Added the following test to the sayTime routine to fix for when the minutes are less than 10 to say “eight-oh-eight” for 8:08 it said “eight-eight” with the original scripting

if myMinute < 10 then set myMinute to "0" & (myMinute as text)

Sorry for switching it all to Mail instead of Thunderbird, as I don’t use that app. Got lazy and didn’t switch it all back.

edit: Here is the edited script in its entirety:

(*This script is copyright by Curtranhome - All Rights Reserved - Complete Access to this script is for everyone, but will need to present the script to Curtranhome*)
tell application "iTunes"
	activate
	play the playlist ("Skillet")
end tell

set volume 6

delay (10)
set weatherurl to "http://weather.yahoo.com/"
set city to "Sacramento Ca"

tell application "Safari"
	activate
	make new document with properties {URL:weatherurl}
	repeat
		set docstate to (do JavaScript "document.readyState" in document 1)
		if docstate is "complete" then
			exit repeat
		end if
	end repeat
	delay 5
	do JavaScript "document.forms[2].elements[0].value = \"" & city & "\"" in document 1
	do JavaScript "document.forms[2].submit()" in document 1
	delay 5
	set websitesource to source of document 1
	close document 1
	
	try
		set todayoffset to offset of "<strong>Today:</strong>" in websitesource
		set partwebsitesource to (characters todayoffset through -1 of websitesource) as text
	on error
		set todayoffset to offset of "<strong>Tonight:</strong>" in websitesource
		set partwebsitesource to (characters todayoffset through -1 of websitesource) as text
	end try
	
	set listoffset to offset of "F" in partwebsitesource
	set todayweather to (characters 28 through (listoffset - 1) of partwebsitesource) as text
end tell

tell application "Mail" to activate

delay (10)

(*Resize windows of iTunes, Safari and Mail*)
tell application "Finder"
	set screen_resolution to bounds of window of desktop
	set screen_width to item 3 of screen_resolution
	set screen_height to item 4 of screen_resolution
end tell


set desired_width to 1000

set side_space to screen_width - desired_width
set left_bound to (side_space / 2)
set right_bound to left_bound + desired_width
set bottom_bound to screen_height
set top_bound to 22 (* for the menu bar *)

try
	tell application "iTunes"
		activate
		set the bounds of the first window to {left_bound, top_bound, right_bound, bottom_bound}
	end tell
end try

try
	tell application "Mail"
		activate
		set the bounds of the first window to {left_bound, top_bound, right_bound, bottom_bound}
	end tell
end try

delay (5)

(*Say the Date*)
set myDate to get (current date)
set myMonth to get month of (current date)
set myDay to get day of (current date)
set myYear to get year of (current date)

set myDay to myDay & "th"


say ("today is: " & myMonth & space & myDay & space & myYear & "!")

(*say the current weather - scripted above*)
tell me
	say "and the weather is: " & todayweather & " degrees"
end tell

(*say the current time*)
sayTime()

delay (600)

(* Quit Mail *)
say "Mail will now quit"
tell application "Mail" to quit

(*say the time after everything is done*)
sayTime()

(*End of Script*)
on sayTime()
	
	set myHour to get hours of (current date)
	set myMinute to get minutes of (current date)
        if myMinute < 10 then set myMinute to "0" & (myMinute as text)
	
	if myHour > 12 then
		set myHour to (myHour) - 12
		set ampm to "PM"
	else
		set ampm to "AM"
	end if
	say "it is now " & myHour & ":" & myMinute & space & ampm
end sayTime

wow, this script is quite entertaining! i have tweaked it a little, and it is a ton of fun. thanks for posting it!

Sorry for not keeping this feed alive for the last couple years, I’ve been busy with school and all… But anywho… Anyone got any ideas to add to this? Now that we have new script updates (since the last post of this feed).

Model: iMac G5
Browser: Safari
Operating System: Mac OS X (10.5)

Hello everyone!

It’s been a couple more years since the last post of this thread and would like to keep it open.

Since the last update, I’ve gained quite a bit more experience in the technology world and would like to post an updated version of the script after all the additions made to it over time as well as some modifications I have made to it to simplify it down. If anyone has any ideas they would like to toss into the mix, by all means do and post your results here!

Let’s see what kind of fun we can have! :smiley:


(*This script is copyright by Curtranhome - All Rights Reserved - Complete Access to this script is for everyone, but will need to present the script to Curtranhome*)
set myHour to get hours of (current date)
if myHour is greater than 12 then
	(*tell application "iTunes"
		activate
		play the playlist ("favorites")
	end tell
	
	set volume 6
	
	delay (10)*)
	set weatherurl to "http://weather.yahoo.com/"
	set city to "Sacramento CA"
	
	tell application "Safari"
		activate
		make new document with properties {URL:weatherurl}
		repeat
			set docstate to (do JavaScript "document.readyState" in document 1)
			if docstate is "complete" then
				exit repeat
			end if
		end repeat
		delay 5
		do JavaScript "document.forms[2].elements[0].value = \"" & city & "\"" in document 1
		do JavaScript "document.forms[2].submit()" in document 1
		delay 5
		set websitesource to source of document 1
		close document 1
		
		try
			set todayoffset to offset of "<span class=\"num\">" in websitesource
			set partwebsitesource to (characters todayoffset through -1 of websitesource) as text
			display dialog "" & partwebsitesource & ""
		on error
			display dialog "Unable to get weather"
		end try
		
		set listoffset to offset of "F" in partwebsitesource
		set todayweather to (characters 19 through (listoffset - 192) of partwebsitesource) as text
		display dialog todayweather
	end tell
	
	tell application "Thunderbird" to activate
	
	(*Say the Date*)
	set myDate to get (current date)
	set myMonth to get month of (current date)
	set myDay to get day of (current date)
	set myYear to get year of (current date)
	
	set myDay to myDay & "th"
	
	
	say ("Today is: " & myMonth & space & myDay & space & myYear & "!")
	
	(*say the current weather - scripted above*)
	tell me
		say ". The current temperature is " & todayweather & " degrees fahrenheit."
	end tell
	
	(*say the time after everything is done*)
	sayTime()
else
	
end if
(*End of Script*)
on sayTime()
	
	set myHour to get hours of (current date)
	set myMinute to get minutes of (current date)
	if myMinute < 10 then set myMinute to "0" & (myMinute as text)
	
	if myHour > 12 then
		set myHour to (myHour) - 12
		set ampm to "PM"
	else
		set ampm to "AM"
	end if
	say "it is now " & myHour & ":" & myMinute & space & ampm
end sayTime

Model: Macbook Pro Early 2015
AppleScript: 2.4
Browser: Google Chrome 43
Operating System: Mac OS X (10.10)

Don’t do this!


set partwebsitesource to (characters todayoffset through -1 of websitesource) as text

By getting the characters you’ve unnecessarily created an enormous list, which can give AppleScript a headache and is very slow.

Do this instead:


set partwebsitesource to text todayoffset through -1 of websitesource


Chris


{ MacBookPro6,1 · 2.66 GHz Intel Core i7 · 8GB RAM · OSX 10.11.1 }
¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯

Dang! This is exactly why I try and keep this alive! Still use the script today too :smiley: