Do you need to automate this on multiple images? The Image Processor script (accessible in Photoshop CS5 and newer via File - Scripts - Image Processor) can resize images to fit maximum H and V dimensions.
I think it can even work on open documents, but I'm not sure whether it can work on the current open document alone.
I'm sure there's a scripting solution that could allow you to do it on an open Photoshop document, but I'm not familiar with any easily obtained offhand.
Note that the Image Processor script can run an action - perhaps you can find a way to combine it with your action.
Thanks for you answer. I need to resize layers within a document, not the entire psd. And
I need to to this with close to 400 files.
As a plan B I have already tought of exporting layers to separate files and then resizing
these using 'Dr Browns Image Processor Pro script'. Then automatically placing
them and aligning them again. It will work but it's a bit of a workaround - will take some
time to do.
I'm still open to suggestions, but I suspect it's not doable without a custom script. Unless
someone thinks of a brilliant combination of commands that will achieve this..
Great tip! The only problem with it is that it's not able to determine if a layer have a landscape or portrait orientation. But I can certainly use this if I split the action in two, running one on portrait orientation layers and one on landscape orientation layers. It will make it easier to resize multiple layers atleast.