If I wanted to write a formula to check if an app like the calculator was open or if the flashlight was on how would I do that?

I'm working on a project and I wanted to create a formula to check if apps were open or if the flashlight was on. How would I best do that?