Lastsnap functionality with motion

With motion you can configure that a snapshot is made every X seconds. The last snapshot is referred to by a symlink, wich you can use in HA with the generic cam module to show that picture.

Now, I don’t want a snapshot taken every X seconds , but I want the image that was taken because of Motion detection being available as a symlink file with a filename that I can use in HA.

Does anybody know a solution for this?

Since I got no reaction here I made this noob-solution, which works. I’m sure someone of you can optimize this:

I created a script:

#!/bin/bash
input="/home/pi/cam/"
f=$(ls "$input"*.jpg -t | head -n1)
rm -f latestsnap.jpg
cp $f latestsnap.jpg'

Made this script executable and have it run every minute by a cron-job.
The Remove/Copy steps are required because of the error I get sometimes that the file already exists