You could use what Apaec wrote or you could even check if your player is in combat or under attack.
if (myPlayer().isUnderAttack() || getCombat().isFighting()) {
//We are in combat, run
}
Are you running this on a vpn or on your own computer? I have a feeling it's got to do with your aspect ratio since the osbot client is not re sizeable.