Use launchd to check every minute that Last.fm is running. If it's not, then start it up.
- Create
com.USERNAME.lastfm.plist
in$HOME/Library/LaunchAgents
- Create
lastfm.sh
in~
- Don't forget to
chmod +x ~/lastfm.sh
- Inform launchd about the new plist by doing
cd $HOME/Library/LaunchAgents && launchctl load com.USERNAME.lastfm.plist