我正在创建一个AppleScript,我需要在Photoshop上对所选图层执行某些操作。
即使所选图层位于组内,如何获取Photoshop上所选图层的列表?
我现在没有要显示的代码,因为这一切都始于拥有所选图层的列表,抱歉。
答案 0 :(得分:2)
所选图层不是JavaScript的artLayer
对象中的属性,并且选中它也不是AppleScript中layer
对象的属性。但是我们可以在PhotoShop中使用AM并使用动作和描述符结果来获取所选图层。因为层可能需要根据是否存在背景层而快速移动,所以我们首先创建一个包含选定索引的数组(代码基于this post),然后我们解析层的名称。
tell application "Adobe Photoshop CS6"
tell document 1
set selectedLayers to paragraphs of (do javascript "
var typeDocument = stringIDToTypeID('document');
var typeItemIndex = stringIDToTypeID('itemIndex');
var typeLayer = stringIDToTypeID('layer');
var typeName = stringIDToTypeID('name');
var typeOrdinal = stringIDToTypeID('ordinal');
var typeProperty = stringIDToTypeID('property');
var typeTarget = stringIDToTypeID('targetEnum');
var typeTargetLayers = stringIDToTypeID('targetLayers');
var selectedLayers = new Array();
var actionRef = new ActionReference();
actionRef.putEnumerated(typeDocument, typeOrdinal, typeTarget);
var actionDesc = executeActionGet(actionRef);
if(actionDesc.hasKey(typeTargetLayers) ){
actionDesc = actionDesc.getList(typeTargetLayers);
var c = actionDesc.count
for(var i=0;i<c;i++){
try{
activeDocument.backgroundLayer;
selectedLayers.push(actionDesc.getReference( i ).getIndex() );
}catch(e){
selectedLayers.push(actionDesc.getReference( i ).getIndex()+1 );
}
}
}else{
var actionRef = new ActionReference();
actionRef.putProperty(typeProperty , typeItemIndex);
actionRef.putEnumerated(typeLayer, typeOrdinal, typeTarget);
try{
activeDocument.backgroundLayer;
selectedLayers.push( executeActionGet(actionRef).getInteger(typeItemIndex)-1);
}catch(e){
selectedLayers.push( executeActionGet(actionRef).getInteger(typeItemIndex));
}
}
var selectedLayerNames = new Array();
for (var a in selectedLayers){
var ref = new ActionReference();
ref.putIndex(typeLayer, Number(selectedLayers[a]) );
var layerName = executeActionGet(ref).getString(typeName);
selectedLayerNames.push(layerName);
}
selectedLayerNames.join('\\n');
")
end tell
end tell