Krisp.ai Powered Status Light - AppleScript for Mac
Since working from home more and having the kids around for summer holiday, my Status Light has been in more use.
The status light shows the family when I'm on a call, and when I'm available to talk to. The problem was though, I was having to set the status (green/red) manually, and normally I forget to do this. This pretty much makes it pointless. I needed a better way to update the status.. automatically!
Krisp.ai
Background noise removal tool
I've also been using a great tool called Krisp. It uses AI to remove background noise when I'm talking on calls, making it great for usage at home.
The other great thing, is that it integrates with every meeting app I use (Teams, Slack, Zoom, etc). This means that Krisp knows when I'm on a call! Bingo!
I asked Krisp.ai if they had an API that I could use to get the call status, but unfortunately they do not (it has been added as a feature request though).
In the light of no official API, I started looking for another method of getting the call status from Krisp. I found that Krisp writes to a log file called kr_audio_dm.log
. Once analysed, there is a log line that represents when Krisp detects a call is in connected and disconnected.
Great.. now to use that info and update the status light.
AppleScript - Krisp Status Checker
A simple script that will run on an interval, checking for call status
To automate the status light using the Krisp call status, I've created a little AppleScript that monitors the log file and determines if I'm in a call or not.
Lets step through it...
Log file locations & state tracking
To ensure that the script does not read every line in the log file each time it runs, the script tracks the last line read and the last matched logline.
The script also sets many of the variables it needs to work here.
Status Light API URLs
Next the script needs the local URLs of the Status Light API, so that it knows what to trigger on call status events.
- When true is found in the log line, meaning a call has started, the
trueUrl
is called - When false is found in the log line, meaning a call has ended, the
falseUrl
is called
The Status Light API accepts a POST request, with an empty JSON body.
There is also a debug
switch, to enable more logging and popup dialogues to show when events are triggered.
Get last state
To ensure the script doesn't read the logfile in full over and over, it keeps the last log line read, and stores it in a file.
It also stores the last matched log line.
Krisp uses log rotation on the log file that is being read, so when then log file lines are less then what is stored in state, it is reset back to 0.
Having the last match log line, helps to ensure when the log is rotated, the last event is not processed again.
Parse the Krisp log file & find matching lines
The logfile is now read into the script, from the last logline parsed. Keeping read times low.
Each line is read and searched for the existence of the runStateCallback
event. When found, the matching line is added to an list object.
Detect if a call was started or ended
For each of the matching log lines, the script does the following:
- Checks that the matched log line is not the same as the last log line processed
- Check if the matched log line, has true or false in it
- If true is found, the Busy HTTP API of the Status Light is called
- If false is found, the Available HTTP API of the Status Light is called
- After each HTTP API call, the matched log line is written to a file
Installing the script & running on an interval
Now that the script works, it needs to run on a regular interval, so that the status can be checked.
To do this, I've made use of the MacOS LaunchAgent feature.
The install.sh
script creates a new LaunchAgent, with the script being called every 20 seconds. This means that the Status Light gets updated with the correct status of my calls pretty quickly :)
Outcome
With the script working, it installed as a reoccurring script, the Status Light is now working amazing!
It very quickly gets updated with the correct status of my calls, and allows my family to easily see when I'm busy.
Very happy with the results. Hope this helps you too.
For the full source code, please visit:
Sign up for DevBytes - Tech, IoT & Cloud
Tech, IoT & Cloud
No spam. Unsubscribe anytime.