javascript - 使用 AppleScript 打开 Photoshop 文件中的所有智能对象
问题描述
我正在使用的图片有很多智能对象层。由于没有官方方法可以一次打开所有智能对象的内容,我正在考虑使用 AppleScript 和 JavaScript 来执行此操作。
但是,当我打开第一个智能对象时,我遇到了一个问题,Photoshop 的焦点移动到了新打开的图片(已经打开的智能对象的内容)。因此,焦点应再次更改为原始文件(具有许多智能对象的文件),以便打开下一个智能对象。
这可能很简单,但我不是很有经验,在过去的几天里,我找不到在 Photoshop 环境中执行此操作的方法。
这是我的代码:
on run
tell application "Adobe Photoshop CS6"
activate
set Doc_Ref to the current document
set Doc_Name to name of Doc_Ref
tell Doc_Ref
set layerList to name of every layer in Doc_Ref whose kind is smart object layer
repeat with currentName in layerList
set current layer to layer currentName
my Edit_Smart_Layer()
end repeat
end tell
end tell
end run
on Edit_Smart_Layer()
tell application "Adobe Photoshop CS6"
do javascript "editSmartLayer(); function editSmartLayer() { function cTID(s) { return app.charIDToTypeID(s); }; function sTID(s) { return app.stringIDToTypeID(s); }; var desc01 = new ActionDescriptor(); executeAction( sTID('placedLayerEditContents'), desc01, DialogModes.NO );};" show debugger on runtime error
end tell
end Edit_Smart_Layer
PS我认为代码还应该检查智能对象层是否可见。
解决方案
解决方案是:
on run {input}
try
tell application "Adobe Photoshop CS6"
activate
set Doc_Ref to the current document
tell Doc_Ref
try
set layerList to name of every layer in Doc_Ref whose kind is smart object layer
on error
display dialog "The active picture does not have Smart Object Layers !"
return input
end try
repeat with currentName in layerList
set current layer to layer currentName
my Edit_Smart_Layer()
tell application "Adobe Photoshop CS6"
set current document to Doc_Ref
end tell
end repeat
display dialog "Opened Smart Objects: " & length of layerList
end tell
end tell
on error
display dialog "Please run Photoshop and open a picture !"
return input
end try
end run
on Edit_Smart_Layer()
tell application "Adobe Photoshop CS6"
do javascript "editSmartLayer(); function editSmartLayer() { function cTID(s) { return app.charIDToTypeID(s); }; function sTID(s) { return app.stringIDToTypeID(s); }; var desc01 = new ActionDescriptor(); executeAction( sTID('placedLayerEditContents'), desc01, DialogModes.NO );};" show debugger on runtime error
end tell
end Edit_Smart_Layer
推荐阅读
- android - 如何将源项目添加到项目中
- python - __init__() 中定义的类属性与类方法定义的属性
- python-3.x - AWS EC2 ubuntu 实例中的 CNTK 安装错误
- mysql - Mysql:新表的“字段列表”中的未知列
- android - android 8.0 api 级别 27 媒体记录器启动失败,音频源语音通话
- javascript - 事件 show.bs.modal 在 .show() 上为内部模态元素触发
- python - 径向迭代一个numpy数组并在Python中通过径向壳计算方差
- mysql - MySQL设置root密码错误
- scala - Selenium Chrome 节点无法使用 Scalatest 解析 kubernetes 上的 url
- batch-file - trying to set a value to a variable in batch