//Hello! This script takes all selected text frames, copies the content out of them, and then deletes them, leaving the whole lot in your clipboard.
//Useful for: Ebooks with a lot of captions that need to be moved into the main body of text, but also maybe other things? Who knows. The world is your oyster.


var textResult = "";

var selection = app.activeDocument.selection;
var selectNo = 0;
for (selectNo = 0; selectNo < selection.length; selectNo++){
	var selectedObject = selection[selectNo];
	try {
		var selectedText = selectedObject.parentStory.texts[0].contents;	
	} catch(e){
		alert("This doesn't seem to be a text frame.");
	}
	textResult = textResult + selectedText + "\r";
	
	if (selectNo == (selection.length - 1)){
		selectedObject.contents = textResult;
		selectedObject.parentStory.texts[0].select(); 
		app.copy();
	}
	selectedObject.remove();
}
	
function replaceText (input, output)  
{  
     app.findTextPreferences = app.changeTextPreferences = NothingEnum.nothing;  
     app.findTextPreferences.findWhat = input;  
     app.changeTextPreferences.changeTo = output;  
     app.activeDocument.changeText();  
     app.findTextPreferences = app.changeTextPreferences = NothingEnum.nothing;   
}  
	
	
//Tell indesign what .indexOf() is, because it's old and confused.
Array.prototype.indexOf = function ( item ) {  
	var index = 0, length = this.length;  
		for ( ; index < length; index++ ) {  
			if ( this[index] === item )  
				return index;  
		}  
	return -1;  
};  