Re: Seconds until next tock
Re: Seconds until next tock
- Subject: Re: Seconds until next tock
- From: "Stockly, Ed via AppleScript-Users" <email@hidden>
- Date: Mon, 19 Aug 2019 18:24:25 +0000
- Arc-authentication-results: i=1; mx.microsoft.com 1; spf=pass smtp.mailfrom=latimes.com; dmarc=pass action=none header.from=latimes.com; dkim=pass header.d=latimes.com; arc=none
- Arc-message-signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=microsoft.com; s=arcselector9901; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-SenderADCheck; bh=Lkv1PdjLOe+3POvCq6Fim6+4c+22nUbNESFyWKfDv1M=; b=NNKqcJLOIUPne7oupr9Po4zRa9Pw9sZ9opP82ofz1HeX1B0pvcJTc8JKK0fkhU/vbmE+Wd1anektn7a4mxKs0zkcc4EZpiX6lTomb2vdouSeqq/TC6uaDsVHCmDSTqAdO7B+fmq83PbcZscUy4q/lG5z76lkbzehqdUeRz8WCqI+k1vYhZsuqLiClveCQsicUr6yCoEpWZuQnpsDz+q4VQTtv1DMgD+vJxQtkuhy07s97MwP+qmaZdeNv4oV47RpBFjomVr5vykK/BUr1AE3pyGb9DX/nyq+1ILMMgrDMkaY6Uun+RZ6+WPz1BTopksx+MvFF70MI8TSmpmS0ahMWA==
- Arc-seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=eUDcOavxi/udhO+tzQrCXZbqbzKsVnllbldUSV4XXXSk+Tmd1a8I8RpjXSed0gfjGifCfSeAvC4fZoQtJRHn3qSkM0uiyxVyIUGDUAj4Ao18ommUIpT+G0Xx1pqtCCrw7hugsPrt7z+etBrgokYuQ55J/dcqNnvbbQlPQTIGi+ZBQm9nwt3vSZ0x4cD897m3o6dn2vctgV8EAEvwec56yRbSjed31VdIeffVAOwLreaJ4u15MkHbY9u/BZyXoq37YF58K/naJTyfQeWIfz4erAKIDoxLlmbH0LwY6mRntkcMTucCV/okpfsYFc8gYhj1sR+Ksba4g8dAH4tviA/pNw==
- Thread-topic: Seconds until next tock
Hey Gil, when I first read your message I thought you were asking for help
resolving that issue, so I did this:
-----------
repeat 4 times
set now to current date
log "The current time is " & time string of now
set secsToNextTock to SecondsUntilNextTock(now, 10, 8)
log "Next tockTime: " & time string of (now + secsToNextTock)
delay secsToNextTock
end repeat
on SecondsUntilNextTock(now, Tock, MinRunSecs)
set nowSec to ((hours of now) * hours) + ((minutes of now) * minutes) +
(seconds of now)
set nextTockSec to ((nowSec + Tock) div Tock) * Tock
repeat
set tockInterval to ((now - nowSec) + nextTockSec) - now
if tockInterval ≥ MinRunSecs then return tockInterval
set nextTockSec to nextTockSec + Tock
end repeat
end SecondsUntilNextTock
————
On 8/17/19, 3:45 PM, "AppleScript-Users on behalf of Gil Dawson via
AppleScript-Users"
<applescript-users-bounces+ed.stockly=email@hidden on
behalf of email@hidden> wrote:
>EXTERNAL SOURCE
>
>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:
>https://nam04.safelinks.protection.outlook.com/?url=https://lists.ap
>ple.com/mailman/options/applescript-users/ed.stockly%40latimes.c
>om&data=02|01|email@hidden|9b57d11319cc4f1c477408d72
>3649936|a42080b34dd948b4bf44d70d3bbaf5d2|0|0|637016787287979299&am
>p;sdata=t5QbdrGFRGRGn/CSh/D/gnQi1LLwe9YwthpYyUBPd6o=&reserved=
>0
>Archives:
>https://nam04.safelinks.protection.outlook.com/?url=http://lists.app
>le.com/archives/applescript-users&data=02|01|ed.stockly@lati
>mes.com|9b57d11319cc4f1c477408d723649936|a42080b34dd948b4bf44d70d3bbaf
>5d2|0|0|637016787287979299&sdata=GfmmR42NDhQGHekBTgtWYhhtbYVfjgw
>oNOE4/JhLkeY=&reserved=0
>
>This email sent to email@hidden
_______________________________________________
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