I am trying to create a script that displays a message when a specific application is launched to alert the user it is not supported and they're using it at their own risk. I was able to get the base script I want to trigger together, but cannot seem to find a way outside of constant loop checking running processes to trigger it (below). I thought maybe a daemon would be my best bet but I can't seem to find a way to know if the application is launched.
#!/bin/bash
# Infinite loop to continuously monitor processes
while true; do
# Check if 'Microsoft OneNote' process is running
if pgrep -x "Microsoft OneNote" > /dev/null; then
echo "Microsoft OneNote process has started!"
fi
# Adjust sleep time as needed to avoid high CPU usage
sleep 5 # Check every 5 seconds, adjust as necessary
done
Anyone have a way to launch a script only at application launch, not by checking if it is running/open?