You don't have to use a script, just use /clearfocus