This was a really handy question for me, even though 3 years old...
The script example given is a little out of date for current CC versions, so I thought I'd update it here with my tweaked version.
This script will maximise square crop to the longest side, regardless what size the base image is - this was particularly useful when faced with 100s of tall portrait images I wanted to force square, without cropping any of the original image out.
I elected to not save the file from within the script, but used PS 'Save as...' in the action so that I could save PNG as JPG without the transparency, and force a white background so that cutouts and jpgs were all treated the same in the end.
Updated script:
// get current active document
doc = app.activeDocument;
// create variables
var bounds, left, top, right, bottom;
// get the current height and width as a numeric value
// (otherwise you'll get '1000 px' as doc.<dimension>)
const height = doc.height.value;
const width = doc.width.value;
if(height > width) {
// offset the left side
left = 0 - (height - width)/2;
top = 0;
// and the right
right = 0 + (width + height)/2;
bottom = height;
} else {
left = 0;
// offset top
top = 0 - (width - height)/2;
right = width;
// and bottom
bottom = 0 + (height + width)/2;
}
bounds = [left, top, right, bottom];
doc.crop(bounds);
Who knew PS could be scripted so easily! Off exploring opportunities now...
Hope this helps someone else.