I was looking to set up a process to watch a file for a specific change. I can run a tail -f file | grep "change I want"
and new lines pop up when that change occurs. I thought to look at Better Touch Tool to see if this was a trigger that I could add and I found the "File or Folder Did Change" option, but I don't see how I can further interrogate the change that occurred. Is this possible with BTT? BTT might not be the best suited option, but I use it for a number of other things, so I wanted to investigate if I could centralize this here as well.
Thanks!
What exactly you mean by "how I can further interrogate the change that occurred." ? You need to check what exactly has been changed or what? What is your use-case?
BTT can't track what exactly did change, it can only give you the note that something did change.
I want to watch a log file and when I see an entry that contains a particular line, I want to call a web hook.
The use-case is that I want to trigger something else when my microphone is in use. I have an app that knows when my microphone is in use (Mute-Me). I can see this in its log files because it adds a line that says "Mic Usage Start", followed later by "Mic Usage End." I want to trigger something in my Home Assistant setup when I see "Start" to change an LED, and reset that LED when I see "Stop".
Maybe you could use oversight for that? It can run scripts when it detects the mic being used:
By specifying an external program to run, users can extend OverSight's functionality. For instance, some users have employed a simple script with OverSight to control an 'on air' light in their home office, automatically turning it on when the microphone is active and off when it's not.
( I have also thought about adding mic / webcam in use triggers, maybe I'll get to these sometime soon)
Thanks - I'll take a look. There's a MacOS app for Home Assistant that tracks these things, but it seems to track it incorrectly when the output device is a digital interface. However, Mute-Me tracks it correctly, which is why I'm trying to hack my way around it. I'm not sure how Mute-Me totally handles it, but when I start a meeting, or open the mic in System Prefs, the physical Mute-Me will light up based on various preference.
Oversight should also work in these cases, AFAIK it's the most reliable of all
1 Like
This worked quite well with oversight, and the options set to call an external program with command line arguments:
#!/bin/sh
device=""
event=""
# Iterate through arguments
while [ $# -gt 0 ]; do
case "$1" in
-device)
shift
device="$1"
;;
-event)
shift
event="$1"
;;
esac
shift
done
url="https://<ha_url>/api/states/sensor.mac_"$device"_status"
curl -X POST \
-H "Authorization: Bearer <token>" \
-H "Content-Type: application/json" \
-d '{"state":"'$event'"}' \
$url
Thanks for the help!
1 Like
Actually, I was wrong, this has the same problem. I must have been testing with my mac speakers set as the active output. When my output is set to my digital USB interface, it sees my mic as "on" even though it's not (and MuteMe accurately sees it as off). Oh well. Will keep digging into other solutions.
I think I settled on a solution, at least in the interim. This might not be the best approach because it leaves it open if I update BTT, but I guess that's ok for now. I added an action at "BTT did Launch" to Execute Shell Script and put this in the script (I guess I still need to figure out the process_id part if I care):
#!/bin/sh
tail -F -n 1 /Users/user/Library/Application\ Support/MuteMe-Client/Muteme-Client_operations.log | while read line; do
if echo "$line" | grep --line-buffered "Mic Usage Start"; then
"/Users/user/Documents/ha_update.sh" -device microphone -event on -process 123
fi
if echo "$line" | grep --line-buffered "Mic Usage End"; then
"/Users/user/Documents/ha_update.sh" -device microphone -event off -process 123
fi
done
And the ha_update.sh
is basically the above script, with some extra attributes added for date/time and process_id.