applescript 在 Illustrator 中查找和替换文本

applescript find and replace text in Illustrator

我试图让这个 applescript 找到占位符文本并根据 return 对话框替换它。也许有人能看出我的错误。

set OrderNumber to text returned of (display dialog "OrderNumber:" default answer "60000")
set CustomerPO to text returned of (display dialog "CustomerPO:" default answer "TBD")
set GarmentColor to text returned of (display dialog "GarmentColor" default answer "ASH GRAY")
set GarmentDescription to text returned of (display dialog "GarmentDescription" default answer "T-Shirt")
set DesignID to text returned of (display dialog "DesignID" default answer "TBD")
set DesignTitle to text returned of (display dialog "DesignTitle" default answer "TBD")
set Location to text returned of (display dialog "Location" default answer "TBD")
set InkColors1 to text returned of (display dialog "InkColors" default answer "WH")

tell application "Adobe Illustrator"
activate
end tell

on replace_chars(this_text, "AAA", OrderNumber)
{this_text, "BBB", CustomerPO}
{this_text, "CCC", GarmentColor}
{this_text, "DDD", GarmentDescription}
{this_text, "EEE", DesignID}
{this_text, "FFF", DesignTitle}
{this_text, "GGG", Location}
{this_text, "HH", InkColors1}
t
set AppleScript's text item delimiters to the search_string
set the item_list to every text item of this_text
set AppleScript's text item delimiters to the replacement_string
set this_text to the item_list as string
set AppleScript's text item delimiters to ""
return this_text
end replace_chars

基本方法是为您感兴趣的文本框添加自定义名称。只需双击 AI 图层面板中的项目,然后输入所需的名称。然后,您可以像这样从 AppleScript 设置文本框的内容:

tell application "Adobe Illustrator"
    tell document 1
        set contents of text of text frame "DesignTitle" to "New Text"
    end tell
end tell

如果您还没有这样做,您还应该为自己准备一份 Adob​​e 的 AI Scripting Reference。虽然很多内容只是对 AI 字典中已有信息的重述,但它确实提供了一些额外的细节以及示例代码。