I decided that having the Midwatch entry query the ARANet4 every night wasn't as useful as an actual log entry as it may have been as an exercise in learning to have Tinderbox query data from outside of Tinderbox. At some point, I'll be running the log away from home on the MBP, though it just occurred to me that I could take that little sensor along with me. Anyway, I digress...
In doing the review this morning, where I learned that a daily review would be more appropriate than a weekly one, it occurred to me that it might be useful to have the $Text of the Midwatch entry contain the calendar events for the next few days.
Now, I don't intend to replicate the functionality of Calendar in Tinderbox; but it might be nice to have a quick reminder of the upcoming events in the next few days. Calendar events have alerts, but I'm sometimes taken by surprise by a Calendar alert because it wasn't "top of mind." (This most frequently happens when Mitzi creates the event. She usually tells me, but sometimes it's weeks before the event and I seldom look at the calendar unless it's to look for conflicts. I'm retired, sue me.)
(As a further aside, Calendar doesn't have a little "Summary" view in MacOS like it does in iOS.)
I knew there were some Calendar Actions for Automator, and so I figured I'd try to do something with Automator and AppleScript.
And, after a few hours of head scratching, searching and consulting ChatGPT and outright guessing, I got something working.
The Automator Actions are Find Calendar Events and Event Summary. I set Find Calendar Events to all events with start dates in the next three days. I started out with five, but that's probably way more than I need. I just need a couple of days' heads-up so I'm not surprised.
Event Summary creates a small block of text with "Summary, Status, Date and Time," for each event.
Those get passed to a Copy to Clipboard action, which does what it says.
Finally, a Run AppleScript action finds the Midwatch note, and pastes the contents of the clipboard into $Text of the Midwatch entry.
The two things I had to figure out were how to identify an existing note in the document, and how to get the contents of the clipboard into an AppleScript variable. (I couldn't figure out how to just set the value of $Text to the clipboard. I guess you can, but I figured out how to set it to a variable first, so that's what I did.) That was just, "set clipboardText to the clipboard as text", and that's the first thing in the script, everything else follows in a "tell application Tinderbox 9" block.
The key thing in the Tinderbox document is that a note is identified by its $Path. Since there's a new Midwatch entry every day, the path changes every day. I was able to re-use the AppleScript that created the $Path for a new note, and just added &"/Midwatch" to the AppleScript variable thePath. Then used "set theContainer to find note in it with path thePath". Then just "tell theContainer" followed by "set value of attribute "Text" to clipboardText" and a series of end tells.
I ran it, and it works! Amazing. It does make me pretty happy when something works, even if it did take a fair amount of effort and feeling stupid.
I'm leaving it there for the moment. I need to package it up so Tinderbox can access it as a "run command" action. That will be incorporated as an edict in the p_Midwatch prototype, and the last step of that edict will be to disable the edict, so it's not running in every Midwatch entry for every day. Just need it to run once when it's created and then disable itself.
So in the morning, I'll review the previous day's entries and take action as appropriate, and look at the Midwatch entry to see what may be on the schedule that day.
I may try to get clever and have the Midwatch entry collect all the children of the previous day whose "reviewed" boolean is false. That would put everything in essentially one view, and as I check off each entry as "reviewed," it should disappear.
But that's tomorrow's project. I'm awarding myself a meritorious afternoon off.
✍️ Reply by email
Originally posted at Nice Marmot 12:45 Friday, 15 March 2024