I have searched around for this and perhaps it's just not possible. But I would like to create a calendar event but not add it to my calendar, but just attach it into an email I'm drafting so it can be sent for the recipient to add to their own calendar.
Seems simple but after some searching, I haven't seen a way to do it.
I don't know how you could do this through the actual Calendar app, but because Calendar supports the iCalendar standard, you could create an ical file in Keyboard Maestro, built up using variables, etc. You'd then email that file to your user.
In theory, this would then show up as a double-clickable item which would add it to their calendar. I haven't tested this, but it should work, as Calendar understands ical files. I know this isn't a full solution, but hopefully it gets you headed in the right direction.
You'd build the iCalendar file in the macro, then send that file via email to the user. The user would then double-click the calendar file to add it to their calendar.
I built the attached as a very simple test, and it seems to work. It first creates a unique ID in Terminal, as that's a required element in the .ics file. Then the variable just contains all the info about the event. Save that to a file, email the file to the user, and the result is a double-clickable event that opens in Calendar.
It's very basic and probably needs a fair bit of work on the date/time bits to make it all "right," but it definitely worked: I was able to add the event I sent myself by double-clicking the attachment.
So I apologize but I want to repeat I think what you did, just to make sure I understand what's going on there.
I dont know what the script uiidgen gen is, but I assume it's some shell script that returns a UUID.
Then you create a variable which basically is THE CONTENTS of a file. And in this case, you created what is the shell contents of an .ics file!
Then you write the contents of that file contents variable out to a file (with a command I had no idea existed).
And then you use the create new mail message KM command, with the file attached, and then tidy up nuking the .ics file.
If that is the case, that is super cool and I didnt know about the write to file command.
So I probably need to reverse engineer a few of the fields you have there. My guess is put in the appropriate date/time format for DSTART, DEND, title got sin SUMMARY and DESCRIPTION? Not sure what DSTAMP is, but I guess the current time the .ics event is created?
Yes, because each .ics file needs a unique ID, and that's a really easy way to get one.
Yes, we're building a Calendar event in the iCalendar format, which macOS and the Calendar app recognize.
Actually, at this point you probably know about as much as I do about the .ics file format :). I just put that one together by copying an example I found online. To make one exactly correct, you'll probably have to do some reading—maybe start on the wikipedia page, but then search as necessary to find out about the fields you want to use.
The method definitely works, though; you'll just have to spend some time learning enough to get the format exactly correct. (For instance, it seems the backslashed spaces aren't necessary, as my event had the backslashes in the text.)