I am attempting to write a BASH script that creates a timestamp (to be written to file) every time a certain string is found within the output of dbus-monitor (parameters specified later in post). The main purpose of my script is to save the time (including milliseconds) and date whenever a song starts playing on Spotify, as it utilizes notifications.
The following command outputs string "Spotify" whenever a song beings playing.
dbus-monitor --session interface='org.freedesktop.Notifications',member='Notify' | grep 'string "Spotify"'
My attempt:
search='string "Spotify"'
found=$(dbus-monitor --session interface='org.freedesktop.Notifications',member='Notify' | grep 'string "Spotify"')
while [ ${search} == ${found} ]; do
    date -u +%Y%M%d-%H%M%S.%N >> timestamp.txt
done
I am assuming the reason of my code's dysfunction is that dbus-monitor continuously runs, therefore preventing the while loop from executing.
man dbus-monitor dbus.man grep, especially about the--line-bufferedoption.