Yes, I'm sure you could do that if you need it.
As in the case of anything which risks corrupting/losing data if it goes wrong, it may be best if it's self-developed, and carefully tested with dummy data.
Studying the code in
this illustrative OF to Merlin script should get you started, and I think you'll find it generally useful to become more fully acquainted with Applescript.