Applescript:在 Photoshop 上获取选定图层的列表
Applescript: Getting list of selected layers on Photoshop
我正在创建一个 AppleScript,我需要在其中对 Photoshop 上的选定图层执行某些操作。
如何在 Photoshop 中获取所选图层的列表,即使所选图层位于组内?
我现在没有要显示的代码,因为这一切都是从获得选定图层的列表开始的,抱歉。
所选图层不是 JavaScript 的 artLayer
对象中的 属性,并且所选图层也不是 AppleScript 中 layer
对象的 属性 .然而,我们可以在 PhotoShop 中使用 AM 并使用动作及其描述符结果来获取选定的图层。因为图层可能需要 swift 取决于是否有背景图层,我们首先创建一个具有选定索引的数组(代码基于 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
我正在创建一个 AppleScript,我需要在其中对 Photoshop 上的选定图层执行某些操作。
如何在 Photoshop 中获取所选图层的列表,即使所选图层位于组内?
我现在没有要显示的代码,因为这一切都是从获得选定图层的列表开始的,抱歉。
所选图层不是 JavaScript 的 artLayer
对象中的 属性,并且所选图层也不是 AppleScript 中 layer
对象的 属性 .然而,我们可以在 PhotoShop 中使用 AM 并使用动作及其描述符结果来获取选定的图层。因为图层可能需要 swift 取决于是否有背景图层,我们首先创建一个具有选定索引的数组(代码基于 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