• 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
Seconds until next tock
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Seconds until next tock


  • Subject: Seconds until next tock
  • From: Gil Dawson via AppleScript-Users <email@hidden>
  • Date: Sat, 17 Aug 2019 15:45:17 -0700

Hi--

I needed something to execute at a regular interval, on the rounded interval
seconds.

--Gil


repeat 4 times
        log "The current time is " & time string of (current date)
        delay SecondsUntilNextTock(20, 3)
end repeat


-->
(*The current time is 3:26:43 PM*)
(*The current time is 3:27:00 PM*)
(*The current time is 3:27:20 PM*)
(*The current time is 3:27:40 PM*)

on SecondsUntilNextTock(Tock, MinRunSecs)
        set Now to current date
        set NowSec to ((hours of Now) * hours) + ((minutes of Now) * minutes) +
(seconds of Now)
        set LastTock to (NowSec div Tock) * Tock
        set LastTockTime to Now - NowSec + LastTock
        set NextTockTime to LastTockTime + Tock
        set SecsUntilNextTock to NextTockTime - Now
        repeat until SecsUntilNextTock ≥ MinRunSecs -- if the next execution
would come too soon...
                set NextTockTime to NextTockTime + Tock  --skip an interval
                set SecsUntilNextTock to NextTockTime - Now
        end repeat
        return SecsUntilNextTock
end SecondsUntilNextTock
 _______________________________________________
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

  • Follow-Ups:
    • Re: Seconds until next tock
      • From: "Stockly, Ed via AppleScript-Users" <email@hidden>
    • Re: Seconds until next tock
      • From: Shane Stanley via AppleScript-Users <email@hidden>
    • Re: Seconds until next tock
      • From: Maik Waschfeld via AppleScript-Users <email@hidden>
  • Next by Date: Re: Seconds until next tock
  • Next by thread: Re: Seconds until next tock
  • Index(es):
    • Date
    • Thread