Batch action with max size

I am trying to write an action i can use to batch resize loads of photos but have come up against an issue:

I want to set a max height and width so that if an image exceeds either it will resize accordingly (constraining proportions). But i ONLY want to do with if the width or height EXCEDES the max value so if they both fall within the constraints then no resizing happens.

How can i do this?