通过 AppleScript 或 JavaScript 在 PS 中选择裁剪预设

问题描述 投票:0回答:1

我真的很感激能在这个问题上提供一些帮助。

有一个更大的 AppleScript,它可以打开文件夹内的图片并对它们应用不同的 Photoshop 步骤。

脚本通过使用选择并通过系统事件(键代码)执行 PS 裁剪工具,在其生命周期中多次裁剪图片。最后一次裁剪必须具有特定尺寸,我将其保存为具有特定名称的裁剪预设。问题是我找不到告诉 AppleScript 使用该预设的方法。我通过设置所需的尺寸(裁剪边界、图像事件等)尝试了各种裁剪方法,但所有这些方法都会在裁剪后删除像素,我需要它们不被删除,因为 PS 裁剪工具允许。此外,PS 裁剪工具会根据新尺寸更改结果图片的纵横比,并且在此过程中不会扭曲图像(不确定我是否解释正确)。所以我必须想办法以某种方式切换到该裁剪预设。

Java 脚本的解决方案也很有用。即使我不知道如何用 JavaScript 编程,我也可以告诉 AppleScript 在特定点运行 JavaScript 文件。 Java 脚本必须在已经打开的图片上工作,预设的名称必须是硬编码的(无需询问用户),并且执行裁剪。 我以前用 Indesign 做过一些类似的事情,但到目前为止 PS 没有运气。

tell application "Adobe InDesign 2021"
set my_pdf_export to get the name of every PDF export preset
set my_pdf_choice to (choose from list my_pdf_export) as string
tell active document
export format PDF type to PathToDocuments & (characters 1 thru -6 of doc_name) & ".pdf" using my_pdf_choice
end tell

提前感谢您花时间帮助我解决问题!

javascript applescript crop photoshop applescript-objc
1个回答
0
投票

我没有 Indesign 来测试我的猜测,但查看应用程序的 AppleScript 字典,我认为脚本中的 my_pdf_choice 只是一个字符串。相反,您需要对该对象的引用 - PDF 导出预设 my_pdf_choice:

set PathToDocuments to (path to documents folder) as text -- HFS path

tell application "Adobe InDesign 2021"
set my_pdf_export to get the name of every PDF export preset
set my_pdf_choice to (choose from list my_pdf_export)
if my_pdf_choice is false then
-- do nothing if the choice cancelled
else 
set my_pdf_choice to PDF export preset (item 1 of my_pdf_choice) -- THIS, or
-- set my_pdf_choice to PDF export preset (my_pdf_choice as string) -- THIS
tell active document
export format PDF type to PathToDocuments & (characters 1 thru -6 of doc_name) & ".pdf" using my_pdf_choice without showing options
end tell
end if 
end tell

note:从list命令中chose的结果始终是list(即使选择了1个项目)或booleanfalse(取消选择时。始终最好考虑到此行为命令,就像我在回答中所做的那样。

© www.soinside.com 2019 - 2024. All rights reserved.