Need to say time in 12 hour with AM/PM applescript?

Discussion in 'Mac Programming' started by MrLDarragh, May 5, 2010.

  1. MrLDarragh macrumors newbie

    Joined:
    May 3, 2010
    #1
    Code:
    delay 1
    set thetime to (time string of (current date))
    set d to (date string of (current date))
    say "Good morning, "
    delay 1
    say "It is " & d
    say thetime
    Here it is currently is there a way this could be 12 hour?:confused:
     
  2. fredthefool macrumors newbie

    Joined:
    Jun 4, 2008
    #2
    I think the format for the time string your system builds up, depends on the location you live. If you run your system in the US, it should give you the proper formatted AM/PM string, if you reside in some of the countries, where a 24-hour system is standard (as where I live) it will be the other way.
    (I'm pretty shure, there is likely somebody here to correct me, if I'm wrong!)
    So if you run into trouble with that, you can access the properties of your date string individually.

    The following code gets the hours and minutes from your actual date string and should give you the proper output -- in the form you want, as I assume.

    Code:
    set pre to "AM"
    set myHour to hours of (current date)
    set myMinutes to minutes of (current date)
    if (myHour > 12) then
    	set myHour to (myHour - 12)
    	set pre to "PM"
    end if
    say (myHour as string)
    say (myMinutes as string)
    say pre
    
     
  3. MrLDarragh thread starter macrumors newbie

    Joined:
    May 3, 2010
    #3
    Thank you! I can now incorporate that into my script! ;)
     

Share This Page