Skip to content

Using Automator and AppleScript to replace text in an image

For Applescript:

1
2
3
4
5
tell application "Acorn"
    tell document 1
        replace text "$foo$" with "This Is The New String"
    end tell
end tell

For Javascript:

doc.replaceOccurrencesOfString_withString("$foo$", "This Is The New String");

Combine this feature with pre-made templates and you can automate the making of templates, guest tags, or anything else that combines lists of text with images. See below for an example that starts with a simple template. Applescript drives the text replacement along with saving the images as PDF.

set priceList to ["$4.99", "$9.99", "$3.99"]
set itemList to ["Eggs", "Pizza", "Cheese"]


repeat with i from 1 to number of items in priceList

    set price to item i of priceList
    set title to item i of itemList

    tell application "Acorn"
        set doc to open "/Users/gus/Desktop/Coupon Template.acorn"

        tell doc
            replace text "$title$" with title
            replace text "$price$" with price

            set fileName to title & ".pdf"

            web export in "/tmp/" & fileName as PDF

            close without saving

        end tell
    end tell
end repeat