Allows you to send log messages to BBEdit, using a message queue so the caller doesn't have to wait for BBEdit to finish adding the message(s).
NOTE: You can also call it using "Execute a Macro", and passing the arguments in the "with parameter" field. See the coments at the start of the macro for more information.
FEATURES:
You can target multiple BBEdit documents (which I call "Tabs"):
NOTE: Even though the tab names look like file names, there's no actual files on disk unless you save them.
And of course you can take advantage of BBEdit's color-coding, by specifying the appropriate file extension like this:
VERSION HISTORY
1.0 - Initial Release
INSTALLATION
Click to expand
UPGRADE INSTRUCTIONS:
Delete the old macros, or just delete the entire group.
What's the advantages of this over, say, a single semaphored async macro that does the writing? I'm guessing one would be that there's less chance of hitting the maximum concurrent macros limit if you sent a flurry of messages and BBEdit couldn't keep up.
Example logger, lacking some of your fancy bits but with a delay in the AppleScript to spoof BBEdit dragging a bit:
I started that way, but the idea of possibly reaching a limit did bother me. I can't say it really matters, but still.
And honestly, I wrote this because over the course of my programming jobs, I've always had a queued logger, in whatever programming language I was using a the time, and I wanted to see if I could do it in KM/JXA/AppleScript.
The main advantage is speed, although I can't say how much it matters. But if you run the Example macro, you'll probably see it write 2 messages at a time most of the time. That's because when the Queue Watcher retrieves the next message(s) to write, it combines consecutive queued messages to the same tab into one BBEdit write.
I never did a comparison, though, so I could be wrong.
By the way, I've been using chatGPT to figure out how do manipulate BBEdit this way. And I just realized it works if I ask for jxa instead of applescript.
I spent some time working on an update to this that is MUCH faster - by an order of magnitude. Great stuff.
Then, out of the blue, I remembered something I wrote back in 2016, which I still use now in macros that I run every day. Although obviously I haven't checked the results in a while or I would have remembered.
It's a set of macros that do logging, including having timestamps and elapsed time! They do it by writing to a file. And guess what? You can open the file in BBEdit, and BBEdit will refresh it when the file changes.
So it turns out I actually don't need this BBEdit macro - the file version is much better. Sometimes I can be a real moron. Here's the post I made about it on this forum:
I could actually use the "queue" mechanism I wrote to make the "elapsed time" version a little faster, but at this point, all I can do is shake my head.
In case anyone cares, I ended up writing a queued version of the "write to file" logger. It's blazingly fast. I'm still working out a few situations where something crashes, but knock on wood I haven't seen it happen in a while, so maybe it's time to think about releasing it.
Although I suspect nobody really cares about it. Which is fine with me.
Please do post it up @DanThomas as I've been mulling over a process that would involve a queue and it might help me to see your approach. Sorry if that sounds selfish but I don't want to reinvent the wheel if I can help it