try{ if ( app.documents.length > 0 ) { // Make sure the is an open document var doc = activeDocument; // capture the document's name so... if ( doc.layers.length > 1){ // ...if there's more than one layer... var idslct = charIDToTypeID( "slct" ); // ...select the bottom-most layer var desc19 = new ActionDescriptor(); var idnull = charIDToTypeID( "null" ); var ref17 = new ActionReference(); var idLyr = charIDToTypeID( "Lyr " ); var idOrdn = charIDToTypeID( "Ordn" ); var idBack = charIDToTypeID( "Back" ); ref17.putEnumerated( idLyr, idOrdn, idBack ); desc19.putReference( idnull, ref17 ); var idMkVs = charIDToTypeID( "MkVs" ); desc19.putBoolean( idMkVs, false ); executeAction( idslct, desc19, DialogModes.NO ); } if ( doc.activeLayer.isBackgroundLayer == true ) { // see if it's a background layer doc.activeLayer.name = doc.name + "_Background"; // if true then make it a floating layer and rename it with the document name plus "_Background" } } }catch(e){ //catch any errors alert('The command "Convert Background to Layer" is not currently available.'); //let the user know the command isn't available }