You could try using a while-loop to wait for the service to launch:
#!/bin/sh # If the notification daemon isn't running then launch it if ! pgrep -f "notification-daemon" > /dev/null; then /usr/lib/notification-daemon/notification-daemon & fi # Wait for the notification daemon to finish launching while ! pgrep -f "notification-daemon" > /dev/null; do # Set optional delay sleep 0.1 done # Play awesome song (do-doop da-doop doop-doop-doop...) notify-send "Take 5" aplay /home/Me/Music/brubek-clip.wav This should guarantee that you don't continue until the daemon is running (e.g. if for some reason it takes longer than your 0.5 second sleep).
I did a little bit of web-searching for similar posts and found a few that seem relevant:
These all seem to follow the same basic approach - use a loop to wait until the desired condition is met.
UPDATE: It turns out that waiting for the process to start isn't sufficient. In this case you need to wait for the service to become available. You may want to look at the following posts:
How do I run a script on a dbus signal?
A list of available D-Bus services
How to create a daemon which would be listening to dbus and fire script on message
Is there a way to show notification from bash script in Ubuntu?