#target Indesign
var doc = app.activeDocument;
var mySel = app.selection[0];
if (mySel) {
var sb = mySel.geometricBounds;
//https://forums.adobe.com/message/3869567#3869567
var bkp = app.marginPreferences.properties;
app.marginPreferences.properties = {
top:0, left:0, bottom:0, right:0,
columnGutter:0, columnCount:1
};
var newDoc = app.documents.add({
documentPreferences: {pageWidth:sb[3]-sb[1], pageHeight:sb[2]-sb[0]},
});
var mySelCopy = mySel.duplicate(newDoc.pages[0]);
mySelCopy.move([0,0]);
app.marginPreferences.properties = bkp;
writeFile = File.saveDialog( 'Save JPG as:' );
app.jpegExportPreferences.jpegQuality = JPEGOptionsQuality.MAXIMUM;
app.jpegExportPreferences.exportResolution = 300;
newDoc.exportFile(ExportFormat.JPG, writeFile);
newDoc.close(SaveOptions.no);
}