Script to add MailTags to messages that have been added to OF?

I’ve been using OF3 on iPad to add emails, which works great except…on my Mac I have been using an AppleScript that adds a Mail message to OF2 and tags the original email with InOmniFocus. Now when I work on iOS, I end up with a lot of emails in OF that are still untagged.

I’m wondering if anyone has written a script that will search existing OF tasks (maybe limited to the last 3 days?) for message: links, and add a MailTag to the corresponding email messages.

I got this working in bash to search the note (where note contents have been saved to test.txt and pull out the message URL but have been having trouble (probably just escaping) getting it integrated in AppleScript.

grep -o '<message:.*' test.txt | sed 's:^.\(.*\).$:\1:'