• Open Menu Close Menu
  • Apple
  • Shopping Bag
  • Apple
  • Mac
  • iPad
  • iPhone
  • Watch
  • TV
  • Music
  • Support
  • Search apple.com
  • Shopping Bag

Lists

Open Menu Close Menu
  • Terms and Conditions
  • Lists hosted on this site
  • Email the Postmaster
  • Tips for posting to public mailing lists
Re: Modify Time Of Day script
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: Modify Time Of Day script


  • Subject: Re: Modify Time Of Day script
  • From: "Nigel Garvey" <email@hidden>
  • Date: Tue, 31 Oct 2017 10:41:32 +0000

"dan d." wrote on Mon, 30 Oct 2017 21:55:24 -0400

>One of the scripts that comes with osx is Time Of Day.applescript.

>The script speaks date and time.
>
>I have been trying to seperate these and assign them to seperat
keys,ie. "t"
>for time and "d" for date.
>
>Looking at the script I have come to realize it is beyond my beginner/'s
>skills
>to divide the original into these two functions because much of it is
not
>understood.

I'm not surprised! It contains quite a lot of waffle and flits around in
its handling of the hour and the minutes. Adapting it to speak just the
date, you might do something like this:

  (*
  Speaks the date.
  Adapted from Apple's "Time Of Day.applescript" script, whose copyright notice
follows.
  *)
  (*
   Speaks the  date and time of day

   Copyright 2008 Apple Inc. All rights reserved.

   You may incorporate this Apple sample code into your program(s) without
   restriction.  This Apple sample code has been provided "AS IS" and the
   responsibility for its operation is yours.  You are not permitted to
   redistribute this Apple sample code as "Apple sample code" after having
   made changes.  If you're going to redistribute the code, we require
   that you make it clear that the code was descended from Apple sample
   code, but that you've made changes.
   *)

  on isVoiceOverRunning()
    tell application "System Events" to return (name of processes contains
"VoiceOver")
  end isVoiceOverRunning

  on isVoiceOverRunningWithAppleScript()
    if (isVoiceOverRunning()) then
      -- is AppleScript enabled on VoiceOver --
      tell application "VoiceOver"
        try
          set x to bounds of vo cursor -- This will presumably error if not.
          return true
        on error
          return false
        end try
      end tell
    else
      return false
    end if
  end isVoiceOverRunningWithAppleScript

  set currentDate to (current date)
  set currentDate to ((currentDate's month) as text) & " " & (currentDate's day)

  if (isVoiceOverRunningWithAppleScript()) then
    tell application "VoiceOver"
      output currentDate
    end tell
  else
    say currentDate
    delay 2
  end if

'((currentDate's month) as text)' works for English, but I'm not sure
how it's translated on machines set up for other languages.
Interestingly, although the string which finally gets spoken is
something like "October 31", what's actually _said_ on my machine here
in the UK is "The thirty-first of October"!

A time-only version of the script might look like this:

  (*
  Speaks the time.
  Adapted from Apple's "Time Of Day.applescript" script, whose copyright notice
follows.
  *)
  (*
   Speaks the  date and time of day

   Copyright 2008 Apple Inc. All rights reserved.

   You may incorporate this Apple sample code into your program(s) without
   restriction.  This Apple sample code has been provided "AS IS" and the
   responsibility for its operation is yours.  You are not permitted to
   redistribute this Apple sample code as "Apple sample code" after having
   made changes.  If you're going to redistribute the code, we require
   that you make it clear that the code was descended from Apple sample
   code, but that you've made changes.
   *)

  on isVoiceOverRunning()
    tell application "System Events" to return (name of processes contains
"VoiceOver")
  end isVoiceOverRunning

  on isVoiceOverRunningWithAppleScript()
    if (isVoiceOverRunning()) then
      -- is AppleScript enabled on VoiceOver --
      tell application "VoiceOver"
        try
          set x to bounds of vo cursor -- This will presumably error if not.
          return true
        on error
          return false
        end try
      end tell
    else
      return false
    end if
  end isVoiceOverRunningWithAppleScript

  set currentDate to (current date)
  set currentHour to currentDate's hours

  --  readjust the hour for 12 hour time
  if (currentHour ≥ 12) then
    set amPM to "PM"
  else
    set amPM to "AM"
  end if
  set currentHour to (currentHour + 23) mod 12 + 1

  --  make minutes below 10 sound nice (with a leading 0)
  set currentMinutes to currentDate's minutes
  set currentMinutes to text 2 thru -1 of (100 + currentMinutes as text)

  set currentTime to (currentHour as text) & ":" & currentMinutes & " " & amPM

  if (isVoiceOverRunningWithAppleScript()) then
    tell application "VoiceOver"
      output currentTime
    end tell
  else
    say currentTime
    delay 2
  end if


NG
 _______________________________________________
Do not post admin requests to the list. They will be ignored.
AppleScript-Users mailing list      (email@hidden)
Help/Unsubscribe/Update your Subscription:
Archives: http://lists.apple.com/archives/applescript-users

This email sent to email@hidden

  • Prev by Date: Modify Time Of Day script
  • Next by Date: Best way to orderly display dialogs etc.
  • Previous by thread: Modify Time Of Day script
  • Next by thread: Re: Modify Time Of Day script
  • Index(es):
    • Date
    • Thread