The solution proposed might be a bit specific for my particular setup, but hopefully useful to someone out there.