By script do you mean "Actions" in PhotoShop? If so, bring up the Action pallet, click on the hamburger menu and select "Insert Conditional".
There are a bunch of different conditions but the first one that comes up is "If document is landscape" then it gives you an option to run one script if "yes" or another script if "no".
-KeithP