How to check the global status of an object

if (!activeDocument.pageItems[1].locked) {
alert('Item not locked');
activeDocument.pageItems[1].selected = true;
}
For the user the Path is locked, for the script — no, but also not selected

Solution

var item = activeDocument.pageItems[2];
var itemState = [];
itemState[0] = item.locked ? true : false;
itemState[1] = item.hidden ? true : false;
checkParentState(item, itemState);alert('Item state\n' + 'locked: ' + itemState[0] + '\n' +
'hidden: ' + itemState[1]);
function checkParentState(item, arr) {
var prnt = item.parent;
try {
switch (prnt.typename) {
case 'GroupItem':
if (prnt.locked) arr[0] = true;
if (prnt.hidden) arr[1] = true;
checkParentState(prnt, arr);
break;
case 'Layer':
if (prnt.locked) arr[0] = true;
if (!prnt.visible) arr[1] = true;
checkParentState(prnt, arr);
break;
}
} catch (e) {}
}
Recursion will detect any combination of statuses

--

--

Get the Medium app

A button that says 'Download on the App Store', and if clicked it will lead you to the iOS App store
A button that says 'Get it on, Google Play', and if clicked it will lead you to the Google Play store