Here're two functions to get pathItem index and name. If no path is selected getPathIndex()
will return -1, getPathName()
will throw an error, handle it how you want. Note that if several paths are selected, the function will work only on the last one: I don't think it's possible to iterate several selected paths.
function getPathIndex()
{
var ref = new ActionReference();
ref.putProperty(charIDToTypeID("Prpr"), charIDToTypeID("TrgP"));
ref.putEnumerated(charIDToTypeID("Dcmn"), charIDToTypeID("Ordn"), charIDToTypeID("Trgt"));
var desc = executeActionGet(ref);
return desc.getInteger(charIDToTypeID("TrgP"));
}
function getPathName()
{
var ref = new ActionReference();
ref.putProperty(charIDToTypeID("Prpr"), charIDToTypeID("PthN"));
ref.putEnumerated(charIDToTypeID('Path'), charIDToTypeID('Ordn'), charIDToTypeID('Trgt'));
try
{
var desc = executeActionGet(ref);
}
catch (e)
{
// handle error
return '';
}
return desc.getString(charIDToTypeID("PthN"));
}