fitToArtb();
function fitToArtb () {
try {
var i, j;
for ( i = 0; i < activeDocument.artboards.length; i++ ) {
for ( j = 0; j < selection.length; j++ ) {
selection[ j ].selected = false;
j--;
}
activeDocument.artboards.setActiveArtboardIndex ( i );
activeDocument.artboards[ i ].rulerOrigin = [ 0, 0 ];
activeDocument.rulerOrigin = [ 0, 0 ];
activeDocument.selectObjectsOnActiveArtboard ();
selection[ 0 ].width = Math.abs ( activeDocument.artboards[ i ].artboardRect[ 2 ] );
selection[ 0 ].height = Math.abs ( activeDocument.artboards[ i ].artboardRect[ 1 ] );
selection[ 0 ].top = Math.abs ( activeDocument.artboards[ i ].artboardRect[ 1 ] );
selection[ 0 ].left = 0;
}
} catch ( e ) {
alert ( e.line + '\n' + e.message );
}
}