An AppleScript “current time” example

AppleScript time FAQ: Can you share an AppleScript example that shows how to work with the current time?

If you ever need an AppleScript current time example, or an AppleScript to parse and format the current time, I hope this following script will be helpful. This AppleScript script gets the current time, formats it, and then speaks the current time back to you in a human-friendly format:

say "The current time is " & getTimeInHoursAndMinutes() using "Vicki"

on getTimeInHoursAndMinutes()
	
  -- Get the "hour"
  set timeStr to time string of (current date)
  set Pos to offset of ":" in timeStr
  set theHour to characters 1 thru (Pos - 1) of timeStr as string
  set timeStr to characters (Pos + 1) through end of timeStr as string

  -- Get the "minute"
  set Pos to offset of ":" in timeStr
  set theMin to characters 1 thru (Pos - 1) of timeStr as string
  set timeStr to characters (Pos + 1) through end of timeStr as string

  --Get "AM or PM"
  set Pos to offset of " " in timeStr
  set theSfx to characters (Pos + 1) through end of timeStr as string

  return (theHour & ":" & theMin & " " & theSfx) as string

end getTimeInHoursAndMinutes

When this AppleScript current time script is run, your computer will say something like "The current time is eleven fifty-five a.m."

(FWIW, I needed to create an AppleScript current time script like this for my Mac speech recognition work. See my Mac speech recognition software review, and my Mac Java speech recognition software project pages.)