Alfred

How to check the milk truck's schedule using perl and Alfred

when.png

milk.png

I buy milk from the dairy farm next door. They milk twice a day, at about 5 AM and 5 PM. The milk truck picks up the milk every other day, not long after the morning milking. On days the milk truck comes, I can only get milk after the evening milking. On days it doesn't come, I can get milk any time.

This is the line of perl I use to check when I can get milk:

print int((time()-14400)/86400) % 2 ? "After 5:00." : "Any time."

time() returns the number of seconds since the Unix Epoch (January 1, 1970). Next, I subtracted 14,400 seconds (four hours), my offset from Coordinated Universal Time. Then I divided by 86,400 seconds (one day) and converted to an integer, which gives me the number of days since the epoch. The modulo operation finds the remainder after dividing by two, telling me whether this is an even or odd day, and printing the appropriate message accordingly.

A workflow to execute this perl script via Alfred is attached.

Syndicate content