It's a little complicated, but mostly because of the order of things, in addition to the basic syntax, etc.
#target illustrator
function test(){
var doc = app.activeDocument;
app.executeMenuCommand("Clipping Masks menu item");
var thisClipItem;
var esc = 50; // make sure to have an escape route for the while statement
while(doc.selection.length != 0 && esc > 0){
esc--;
thisClipItem = doc.selection[0];
doc.selection = null;
thisClipItem.parent.selected = true;
app.doScript("CropArt","CropArtSet");
doc.selection = null;
app.executeMenuCommand("Clipping Masks menu item");
}
};
test();
You've got to keep the selection 'juggled' so that the right things are selected when you want them. In this case, we get all of the clipping masks using the selection command, but then in order to use the Crop, we have to deselect all but one of the clipping paths, select the parent group to get the clip and its art both, then use Crop and deselect the result, and then make sure to select the clipping paths again. The while loop is supposed to quit when we are no longer able to select any clipping paths, but in case things go wrong there's an esc variable- right now it's set to 50, make sure this number is larger than your expected clipping paths.