A sheriff has warned the courts will "do all they reasonably can" to protect police officers who come under attack while on duty.