//script by chegr

var sel = activeDocument.selection;

if (sel.length != 0) {

    //duplicate selection
    for (i = 0; i < sel.length; i++) {
        new_dup = sel[i].duplicate();
        new_dup.selected = true;
        sel[i].selected = false;
    }

    //group
    app.executeMenuCommand("group");
    var object = app.activeDocument.selection[0];

    //measure group's bounds
    var bounds = new Array();
    bounds = object.geometricBounds;

    //remove group
    object.remove();

    //create new rectangle based on bounds
    //top, left, width, height
    var rect = activeDocument.activeLayer.pathItems.rectangle(bounds[1], bounds[0], bounds[2] - bounds[0], bounds[1] - bounds[3]);
    rect.selected = true;

    //remove stroke
    var noColor = new NoColor();
    rect.strokeColor = noColor;

    //fit to rect
    var ab = activeDocument.artboards.getActiveArtboardIndex();
    activeDocument.fitArtboardToSelectedArt(ab);

    //remove rect
    rect.remove();

    //restore selection
    selection = sel;

} else {
    alert('Select paths to fit artboard to');
}