var destFolder = null;
destFolder = Folder.selectDialog( 'Select the folder where you want to save the exported files.', app.activeDocument.path );

var baseDestName = app.activeDocument.name;

if (baseDestName.indexOf('.') < 0) 
{
    //nothing
} else {
    var dot = baseDestName.lastIndexOf('.');
    baseDestName = baseDestName.substring(0, dot);
}

var activeArtboard = app.activeDocument.artboards[app.activeDocument.artboards.getActiveArtboardIndex()];

if (destFolder != null)
{
    	// iOS 7
	exportFileToPNG24(60,"icon-60"); // iPhone App Icon Non-Retina
	exportFileToPNG24(120,"icon-60@2x"); // iPhone  App Icon
	exportFileToPNG24(76,"icon-76");  // iPad App Icon Non-Retina
	exportFileToPNG24(152,"icon-76@2x"); // iPad App Icon
	exportFileToPNG24(40,"icon-40");  // Spotlight Non-Retina
	exportFileToPNG24(80,"icon-80@2x"); // Spotlight
	exportFileToPNG24(29,"icon-Small"); // Settings Non-Retina
	exportFileToPNG24(58,"icon-Small@2x"); // Settings

    	// iOS 6.1 and Earlier
    	exportFileToPNG24(57,"icon"); // iPhone Non-Retina App Icon
	exportFileToPNG24(114,"icon@2x"); // iPhone App Icon
	exportFileToPNG24(72,"icon-72"); // iPad Non-Retina App Icon
	exportFileToPNG24(144,"icon-72@2x"); // iPad App Icon
    	// iPhone Spotlight and Settings handled by 29 and 58
	exportFileToPNG24(50,"icon-50"); // iPad Spotlight and Settings Non-Retina
	exportFileToPNG24(100,"icon-50@2x"); // iPad Spotlight and Settings 
	exportFileToPNG24(512,"iTunesArtwork");

}

function exportFileToPNG24(iconSize, name) 
{ 
	var scale = iconSize / activeArtboard.artboardRect[2] * 100;
	
	if ( app.documents.length > 0 ) 
	{
		var exportOptions = new ExportOptionsPNG24();
		var type = ExportType.PNG24;
		var fileSpec = new File ("" + destFolder + "/" + name );
		exportOptions.verticalScale = scale;
		exportOptions.horizontalScale = scale;
		exportOptions.antiAliasing = true;
		exportOptions.transparency = true;
		exportOptions.artBoardClipping = true;
		app.activeDocument.exportFile (fileSpec, type, exportOptions);
	}
}