There are some erros on your code.
First of all,using a try/catch statement to check if a layer have a property is not the best way:
// If the layer has the property, invoke the function with the property as input
try{//wrong
myProperty = myLayer.property("sourceText");
convertToKeyframes(myProperty);
}catch(err){
}
You must do it by a if/else statement, and in your case, what you need to check is if the current layer is a TextLayer object, because all text layers must have a sourceText property.
Second you are trying to access sourceText property on a wrong way. You must access it using full property spec, and it’s better to use the matchName instead of the name:
if(myLayer instanceof TextLayer){
myProperty = myLayer.property(" ADBE Text Properties").property("ADBE Text Document");
//Do stuff
}
Other thing I can see is if you want to do this for multiple comps you must encapsulate your code on a function with the current comp as parameter, and then iterate throug the comps:
function bakeExpressions(curComp){
// Check if something is selected and if selection it is a Composition...
//...
}
selection = app.project.selection;
for(var curComp in selection){
bakeExpressions(curComp);
}