Bring app window to focus using a script?

Is there a way to script bringing the last opened app window to focus?

I believe this is possible with i3. Ive combined i3 and xfce in less than 2m for the best of both worlds. ive asked about its potential risks just in case and i havent gotten a response yet.