The problem is to devise a formula for use in a macro or batch to re-size an image so that the longest side is a fixed length. So if the target size was (say) 800px, a 300×600 image would become 400×800px and a 2000×500px imge would become 800×200px.
Firstly, ensure that you have an unlocked pixel layer. Select the move tool. In the Transform panel, ensure that the width and height are linked.
Set Width as min(800, 800×w/h)
Given that the layers are linked, this will automatically set the height.
Now select Document > Clip Canvas. This removes the tranparent background.
One curious outcome is that for a 3000×4000 portrait image, after a successful transform/clip, The Transform panel gives the dimensions as width: 800:px by height:600px. The Document Resize gives it (correctly) as width:600px by height:800px.