I setup things at work to auto-pause amarok when I lock the screen using kdesktop_lock. There were some example scripts that worked by checking the screen blank status using dcop in a never-ending while loop and sleeping, but I didn't want that many dcop calls constantly being spawned. These steps need to be done as root, unless you have some custom setup.
First, create the following shell script as /usr/bin/kdesktop_lock.sh:
#!/bin/sh
amarok_status=`dcop amarok player status`
amarok_is_playing=`dcop amarok player isPlaying`
if [ "x$amarok_is_playing" = "xtrue" -a $amarok_status -ne 1 ]; then
dcop amarok player pause
fi
/usr/bin/kdesktop_lock.real $*
if [ "x$amarok_is_playing" = "xtrue" ]; then
dcop amarok player play
fi
This dpkg-divert stuff is just so debian package upgrades won't clobber the setup.
/usr/sbin/dpkg-divert --divert /usr/bin/kdesktop_lock.real --rename /usr/bin/kdesktop_lock
Then setup a symlink from kdesktop_lock.sh to kdesktop_lock, and fix modes on the shell script:
ln -s /usr/bin/kdesktop_lock.sh /usr/bin/kdesktop_lock chmod a+x /usr/bin/kdesktop_lock.sh
Now when you lock your screen an amarok is playing, it should pause your music. When you unlock the screen, it will automatically resume.


