#!/bin/bash
dbus-monitor --session "type='signal',interface='org.freedesktop.ScreenSaver'" |
while read x; do
case "$x" in
# You can call your desired script in the following line instead of the echo:
*"boolean true"*) echo SCREEN_LOCKED;;
*"boolean false"*) sh -c "echo SCREEN_UNLOCKED; pulseaudio -k";;
esac
done &
Have this run when starting Gnome/KDE etc seems to work okay.
It isn't ideal. Saves you running pulseaudio -k manually, that's all.