Main .jsx
function getSelectedLayer() {
SL = app.project.activeItem.selectedLayers;
//return selected layer index or any other property
return SL.length != 0 ? SL[0].index : null
};
main .js in HTML
var csInterface = new CSInterface();
setInterval(() => {
csInterface.evalScript(“getSelectedLayer()”, function (result) {
if (result !== “null”) {
//Do something when layer is selected
$(‘#elemID’).html(‘Selected Layer index: ‘+ result);
}
});
}, 1000); // checks selected layer every one second