KevinCork KevinCork - 3 months ago 8
AppleScript Question

AppleScript : incrementing and reseting after a day

I have an AppleScript saved as an app, I run it a few time a days, and I want to added a counter.

property currentCount : 0
increment()

on increment()
set currentCount to currentCount + 1
display dialog "Count is now " & currentCount & "."
end increment


This is adding 1 each time the script is running even if I close and open it again, but how can I reset it ?

I mean the goal is to count the number of "case" every day and then start over the day after.

How can I just reset automatically the next day ?

Cheers

Answer

Try this, it uses an additional property for the current date.

property today : missing value
property currentCount : 0

increment()

on increment()
    set currentDate to short date string of (current date)
    if currentDate is not today then
        set today to currentDate
        set currentCount to 0
    end if
    set currentCount to currentCount + 1
    display dialog "Count is now " & currentCount & "."
end increment