applescript在Illustrator中查找并替换文本

时间:2015-01-20 18:03:01

标签: applescript

我正在尝试使用这个AppleScript来查找占位符文本并根据返回对话框替换它。也许有人能看出我的错误。

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

1 个答案:

答案 0 :(得分:1)

基本方法是将自定义名称添加到您感兴趣的文本框架中。只需双击AI的图层调板中的项目,然后键入所需的名称。然后,您可以在AppleScript中设置文本框架的内容,如下所示:

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

如果您还没有这样做,那么您也应该获得一份Adobe AI Scripting Reference的副本。虽然很多内容只是AI字典中已有的信息,但它确实提供了一些额外的细节以及示例代码。