Read datetimes from file and perform action when each. Topic is solved

Get help with using AutoHotkey (v1.1 and older) and its commands and hotkeys
kashmirLZ
Posts: 53
Joined: 06 Oct 2022, 23:27

Read datetimes from file and perform action when each.

06 May 2024, 06:45

I've a python program which has datetimes.
I'll save those to a file.
I want an AHK script to read that file and do something at those times (give or take 1-min).

1) What format would be best to save the datetimes in so that AHK can read it into a usable data structure?
2) In AHK, how would I read it in?
3) How do I do datetime comparison with current system time?
User avatar
mikeyww
Posts: 27169
Joined: 09 Sep 2014, 18:38

Re: Read datetimes from file and perform action when each.

06 May 2024, 06:53

1) What format would be best to save the datetimes in so that AHK can read it into a usable data structure?
YYYYMMDDHH24MISS
2) In AHK, how would I read it in?
FileRead
3) How do I do datetime comparison with current system time?
EnvSub
kashmirLZ
Posts: 53
Joined: 06 Oct 2022, 23:27

Re: Read datetimes from file and perform action when each.  Topic is solved

07 May 2024, 10:20

Thanks m8.

Code: Select all

SetTimer, checkIfScheduledRightNow, 60000

checkIfScheduledRightNow() {
    scheduleFile := "schedule.txt"
    if !FileExist(scheduleFile) {
        MsgBox, 16, Error, Schedule file not found!
        return
    }
    FileRead, fileContents, %scheduleFile%

    Loop, Parse, fileContents, `n {
        ; Skip empty lines
        if (A_LoopField = "")
            continue
        ; Get current timestamp    
        FormatTime, currentTime,, yyyyMMddHHmm
        ; get this schedule entry
        dateTimeAndDiff := A_LoopField
        MsgBox, Date Time: %dateTimeAndDiff%
        ; get the difference between the two
        EnvSub, dateTimeAndDiff, %A_Now%, minutes
        MsgBox, Difference in mins: %dateTimeAndDiff%
        ; check if it's 1-min before the hour or within the hour
        if (-59 <= dateTimeAndDiff and dateTimeAndDiff <= 1) { 
            FormatTime, formattedTime, %A_LoopField%, h:mm tt
            ToolTipTimer("You're scheduled right now at " formattedTime)
            return
        }
    }
}

Return to “Ask for Help (v1)”

Who is online

Users browsing this forum: No registered users and 92 guests