0

Ive been following the Adobe InDesign CS6 AppleScript Scripting Guide, and I'm trying to change text I have set up.

Currently it works, but it only changes the exact string "Apple" to "Pear"

Is it possible to have findword set up as a list of strings like "apple", "fruit". I tried making it a list but got this error "Invalid value for set property 'find what'. Expected string or nothing,

Also when it changes the text I want to to completely clear the indesign text box and replace it with changeWord

right now if anything comes after "Apple" like Apple123 it will change it to "Pear123". I need it to clear the text box and place changeWord in the text box

Any advice would be greatly appreciated, or just being pointed in the right direction.

Thanks!

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 
Matt
  • 137
  • 2
  • 14

1 Answers1

1

You can use regex, this will replace any words that start with one of the items in the list.

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