我一直在关注Adobe InDesign CS6 AppleScript脚本编写指南,我正在尝试更改我已设置的文本。
目前它可行,但它只会更改确切的字符串" Apple"到" Pear"
是否可以将findword设置为字符串列表,例如" apple"," fruit"。 我试过把它作为一个列表,但得到了这个错误 "设置属性的值无效'找到'。预期的字符串或没有,
当它更改文本时,我想要完全清除indesign文本框并将其替换为changeWord
现在,如果发生任何事情" Apple"像Apple123一样,它会改变为#34; Pear123"。我需要它来清除文本框并将changeWord放在文本框中
任何建议都会非常感激,或只是指向正确的方向。
谢谢!
set findWord to "Apple"
--establish text for change
set changeWord to "Pear"
tell application "Finder" to set indesignFiles to (files of folder "test1" whose name extension is "indd") as alias list
tell application "Adobe InDesign CC 2015"
open indesignFiles
--Clear find text preferences
set find text preferences to nothing
--Clear change text preferences
set change text preferences to nothing
--establish properties for find
set find what of find text preferences to findWord
--establish properties for change
set change to of change text preferences to changeWord
--perform change text operation
tell document 1
change text
end tell
set find text preferences to nothing
set change text preferences to nothing
if modified of active document is true then
tell active document to save
end if
tell active document
export format PDF type to "Macintosh HD:Users:mattsocha:Desktop:Test1:test.pdf" without showing options
end tell
end tell
答案 0 :(得分:1)
您可以使用正则表达式,这将替换以列表中的某个项目开头的任何单词。
set findWord to "(apple|pear|peach|banana)\\w*"
set changeWord to "fruit"
tell application "Adobe InDesign CC 2015"
set find grep preferences to nothing
set change grep preferences to nothing
set find what of find grep preferences to findWord
set change to of change grep preferences to changeWord
tell document 1
change grep
end tell
set find grep preferences to nothing
set change grep preferences to nothing
end tell