• 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: Stop a script at a certain time?
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: Stop a script at a certain time?


  • Subject: Re: Stop a script at a certain time?
  • From: Nigel Garvey <email@hidden>
  • Date: Mon, 20 Dec 2004 21:44:54 +0000

Aaron Rosenblum wrote on Mon, 20 Dec 2004 11:50:40 -0500:

>Is there an easy way to convert from the time in total seconds (as
>returned by "time of (current date)") to a user readable "military" or
>"AM/PM" time string and back in AS? I have been looking around and
>can't seem to find any such functions, but I thought I'd ask.
>
>ie
>
>0600 hours would be 21600 seconds and 21600 seconds would be 0600 hours.
>
>What I'd really like to do is compare two times without the date so
>that I can check it with my script and tell it to quit running if it
>gets to be a certain time.  My thought would be to store the time in
>total seconds and then compare them with LT,GT operators, but I'd like
>to be able to use something more readable for the user so they can
>specify time in AM/PM or even military...

Presumably you're not interested in the odd seconds.

  set t to (time of (current date))

  -- Seconds to military.
  set militaryTime to text 2 thru 5 of ((10000 + t div hours * 100 + t
mod hours div minutes) as string) & " hours"

  -- Seconds to 12-hour.
  tell (10000 + ((t div hours - 1) mod 12 + 1) * 100 + t mod hours div
minutes) as string
    if t < 12 * hours then
      set twelvehourTime to text 2 thru 3 & ":" & text 4 thru 5 & " am"
    else
      set twelvehourTime to text 2 thru 3 & ":" & text 4 thru 5 & " pm"
    end if
  end tell

  -- Military to seconds.
  tell (text 1 thru 4 of militaryTime) as integer to set t to it div 100
* hours + it mod 100 * minutes

  -- 12/24-hour to seconds.
  tell twelvehourTime
    if it ends with "pm" then
      set t to ((text 1 thru 2) mod 12 + 12) * hours + (text 4 thru 5) *
minutes
    else
      set t to (text 1 thru 2) * hours + (text 4 thru 5) * minutes
    end if
  end tell


NG
 _______________________________________________
Do not post admin requests to the list. They will be ignored.
Applescript-users mailing list      (email@hidden)
Help/Unsubscribe/Update your Subscription:

This email sent to email@hidden

  • Prev by Date: Re: changing international text to unicode text
  • Next by Date: Re: Coerce date saved as text back to Applescript's date format?
  • Previous by thread: Re: Stop a script at a certain time?
  • Next by thread: Satimage: non-greedy regexp matching?
  • Index(es):
    • Date
    • Thread