There are lots of threads on this subject here on the forum, with example code. Here’s one:
and here’s another:
Pete.