How to lock xscreensaver on suspend

I’m running Fedora 17 with Gnome3 and xscreensaver. One small problem I had is that resuming from suspend did not automatically lock the screen. Thanks to a helpful post on askubuntu.com, came up with this solution:

#!/bin/bash
case "$1" in
suspend)
export DISPLAY=":0"
su myuser -c "(xscreensaver-command -lock)"
;;
*)
;;
esac