Am I busy? Finding out whether I’m in a meeting or not using AppleScript

Today I’m in a “what’s my status” moon, and following on from setting my Slack status if I’m in a Zoom, here’s an AppleScript to find out whether I’m in a meeting or not:

-- Am I in an event, according to my Calendar?
set now to current date
set theEvents to ""
tell application "Calendar"
	set a_calendar to first calendar where its name = "Peter Rukavina"
	tell a_calendar
		set the_events to (every event whose start date < now and end date > now)
		repeat with an_event in the_events
			set theEvents to theEvents & summary of an_event
		end repeat
	end tell
end tell
return theEvents

With that script in place (and edited to identify you particular calendar in place of mine), you can retrieve your current status from the command line with:

osascript am_I_in_an_event.scpt 

This will return nothing if you’re not in an event, and the name of the event if you are (if you’re in more than one event at the same time, it will simply smush them together).