Simple talking fuzzy logic clock in AppleScript.

I’ve not been playing with AppleScript much, so I opted to reserect it, since Apple was kind enough to provide it with their Developer Tools.

For a simple little test, I made probably one of the worst coded applets in Applescript history; a talking clock. Then, I decided to just go hog wild and make it a little ‘fuzzy’, referring to the date in a less-arcaic way, completing the often-toted ‘relaxed’ feeling of the Mac. That’s marketing for you.

Anyhow, here it is, ugly as sin:

set zDate to current date
try
set zMonth to (month of (zDate)) as string
on error errorMsg
set zMonth to word 3 of errorMsg
end try
try
set zWeekDay to (weekday of (zDate)) as string
on error errorMsg
set zWeekDay to word 3 of errorMsg
end try
set zDay to (day of (zDate)) as string
set zYear to (year of (zDate)) as string
set zTime to (time of zDate)
copy (round (zTime / 3600) rounding down) to zHour
copy (round ((zTime – (zHour * 3600)) / 60) rounding down) to zMinute
copy ((zTime – (zHour * 3600)) – zMinute * 60) to zSeconds
copy ” ” to zMinuteStatus

if zMinute > 12 then
copy ” a quarter past ” to zMinuteStatus
end if
if zMinute > 27 then
copy ” half past ” to zMinuteStatus
end if
if zMinute > 42 then
copy ” a quarter to ” to zMinuteStatus
copy zHour + 1 to zHour
end if

if zHour < 12 then
copy “AM” to mornEve
copy “Morning” to greetEve
else
copy “PM” to mornEve
if zHour < 17 then
copy “Evening” to greetEve
else
copy “Afternoon” to greetEve
end if
if zHour > 12 then
copy zHour – 12 to zHour
end if
end if

copy “Good [[emph +]]” & greetEve & ” Shawn; it is” & zWeekDay & ”, ” & zMonth & ” ” & zDay & ”, ” & ”, at about ” & zMinuteStatus & zHour & ” ” & mornEve to MyTime
say MyTime as string

Pretty painful, huh? I won’t bother to comment on this, other than it could really use some optimization, and you can probably spot a few buglets right off the bat, but for a little 10 minute exercise, I think it holds it’s water fairly well. ;)