Auto-checking if Macro Run on Consecutive Calendar Days

I'd like certain action sets to depend on whether or not the macro was run on consecutive calendar days. (So that's different from the Invoked/Not Invoked constraint, natch, though I could set that to the past 24 hours. Similar function but not exactly what I'm trying for.)

Guessing there'd be ways to do this with system time. I just don't yet understand system time well enough.

The one general method I'm sure would work is to magic-text date info and/or dayofweek into local variables. The macro could then compare a variable representing the current day with a variable representing the last time it finished its actions.

I'm just trying not to overlook whatever way would be most efficient. Ideas?
 

RSF

Well-known member
Local variables would work.

But it seems like using the "Invoked" scheme would be the simplest. You can use that in an IF statement within a macro, not just as a constraint:
Screenshot 2022-07-30 3.35.33 PM.png
Would that work?
 
Local variables would work.

But it seems like using the "Invoked" scheme would be the simplest. You can use that in an IF statement within a macro, not just as a constraint:
View attachment 3117
Would that work?
Thank you, @RSF, but no. Constraint versus IF clause wouldn't make the difference in this case.

For what I have in mind, all that matters is when the actions run. Now that I think about it, the calculation would be simple enough if we could make that "Macro not invoked within the past lv=x amount of time."

Or here's another example to model what I'm going for.

FridayActions run at 1AM
SaturdayActions run at 11PM (or 23:00) Macro sets lv=consec to True
SundayActions not run
MondayActions run at 1AMMacro sets lv=consec to False
TuesdayActions run at noonMacro sets lv=consec to True

See how it's not about a fixed amount of time like 24 hours?
 

RSF

Well-known member
Ah; it's the day of the week being one after the prior day of the week, regardless of hours, yes? Then probably a local variable scheme may work best:
Screenshot 2022-07-30 8.56.03 PM.png

where
  • the shell script puts its output into the "current_day_of_week" variable, and
  • the IF statement tests the concatenated value of "last_run_day_of_week" and "current_day_of_week" against a regular expression of
    (Mon-Tue)|(Tue-Wed)|(Wed-Thu)|(Thu-Fri)|(Fri-Sat)|(Sat-Sun)|(Sun-Mon)
 
Ah; it's the day of the week being one after the prior day of the week, regardless of hours, yes? Then probably a local variable scheme may work best:
View attachment 3118

where
  • the shell script puts its output into the "current_day_of_week" variable, and
  • the IF statement tests the concatenated value of "last_run_day_of_week" and "current_day_of_week" against a regular expression of
    (Mon-Tue)|(Tue-Wed)|(Wed-Thu)|(Thu-Fri)|(Fri-Sat)|(Sat-Sun)|(Sun-Mon)
Think I'm following. I can try that if I can figure out shell scripts.

You know that dayofweek is a magic text option, yes/no?

I don't mind if they're nonnumerical variables. I do want it a little tighter than JUST days of the week, though. Otherwise it could register Friday the fifth and Saturday the 13th as consecutive days.
 
Last edited:

RSF

Well-known member
You know that dayofweek is a magic text option, yes/no?
No; I'missed that (though I'd looked). Good catch. So, use that instead of the shell script, probably, as it's simpler. You'll need to either truncate it to three characters or change the regular expression to use the full day names (Saturday vs. Sat) to switch from shell script to magic-text.

Also, I realized there's a potential flaw in the scheme above, if the macro ran two weeks ago on a Friday, and again for the first time since, today (Saturday).... the macro would say it was run on consecutive days. To handle that possibility, you'll need to add a condition to the If statement to test that the macro was invoked in the last 48 hours.
 
Last edited:

Jacob L

Moderator (Lawsonator)
Magic text on set variable actions give day month and year. You can also get system time, which is the number in milliseconds between the 01/01/1970 and now
 

Dm114

Well-known member
Magic text on set variable actions give day month and year. You can also get system time, which is the number in milliseconds between the 01/01/1970 and now
System time is given in seconds (not milliseconds) in UTC time, not local time.
To convert to local time, you must know your TZ. Attached is a macro I use to calculate local dates and times.
 

Attachments

  • IMG-20220731-WA0001.jpg
    IMG-20220731-WA0001.jpg
    47.5 KB · Views: 9
A programmer friend of mine has been showing me some conversion tool to decode system time. I've been wondering: can people sight read system time, too? Can someone look at a system timestamp and tell what day it was?
 

Snurre

Well-known member
Thank you, @RSF, but no. Constraint versus IF clause wouldn't make the difference in this case.

For what I have in mind, all that matters is when the actions run. Now that I think about it, the calculation would be simple enough if we could make that "Macro not invoked within the past lv=x amount of time."

Or here's another example to model what I'm going for.

FridayActions run at 1AM
SaturdayActions run at 11PM (or 23:00)Macro sets lv=consec to True
SundayActions not run
MondayActions run at 1AMMacro sets lv=consec to False
TuesdayActions run at noonMacro sets lv=consec to True

See how it's not about a fixed amount of time like 24 hours?
In this model, you could use two more variables, set one 'last=dayofmonth' when executed and the other to 'current=dayofmonth' when executed again, then 'if current-last = 1' set your consec to true else false
Would that work?

OR

If you would use (as you mentioned) systemtime it's also possible in the same way, you just check the difference between the two variables
There's 86400 sec in 24 hrs, 3600 in 1 hrs and so on
It could give some more options
 
Last edited:

Dm114

Well-known member
A programmer friend of mine has been showing me some conversion tool to decode system time. I've been wondering: can people sight read system time, too? Can someone look at a system timestamp and tell what day it was?
It's very easy with the Shell script Date command.
 

Jacob L

Moderator (Lawsonator)
System time is given in seconds (not milliseconds) in UTC time, not local time.
To convert to local time, you must know your TZ. Attached is a macro I use to calculate local dates and times.
Oh gosh my mistake!
 
Top