Is there any way to detect if a layer was deleted by the user and then execute some code?
If I delete a layer stored as a variable and then call the variable it tells me that the object is invalid. Comparing it to a null doesn't return true or false as it's not really an object (?).
Not sure which way to go to react to a user deleting a certain layer, created by and crucial to my script.
You could use a try/catch block. Something like this
var a = app.project.item(1).layer("Shape Layer 1").name;
alert("You shouldn't delete the layer");
Another way would be to compare the layer to a null. You must do this before trying to access any of the property. If you do (app.project.item(1).layer("Shape Layer 1") == null) you get a true value if the layer does not exist. However, if you try to access any property of a layer that does not exist, you get an error. Something like this doesn't work (app.project.item(1).layer("Shape Layer 1") == null)