You could create an AppleScript using the AppleScript Editor in
/Applications/Utilites. The syntax is quite easy to follow, and I'd base it on something like this:
tell application "Safari" to activate
tell application "Finder" to activate
This will repeatedly have Safari and Finder get focus while waiting 10s in between. Having 10 seconds as an delay should give you enough time to re-open the editor and click on "stop". Another option would be to use
repeat while instead and to create a stop criterium, like
if exists "/path/to/makeitstop" as POSIX file which would make it stop after a file makeitstop is created.