There’s a Smart Rule script by @BLUEFROG that probably does what you want. Please see the whole thread to understand what it does.