AppleScript can be used to automate the task of locating and replacing text placeholders in text item containers. The following script demonstrates how a Pages template containing text placeholders can be quickly populated using automation and direct interaction with the script user.
NOTE: The following script also demonstrates how placeholder images are replaced with the content image files by changing the value of the file name property of an image.
This script acts as a production assistant by creating a filled-in document based upon a Pages template (in this example a tabbed flyer), after prompting the script user individually for key data elements to be used in the document creation. The script then automatically locates and replaces text and image placeholders with the provided references, greatly reducing the time required to finish the document.
Production Assistant
01
tellapplication "Pages"
02
activate
03
04
display dialog "This script will create a new tab flyer document based upon the information you supply." with icon 1
05
06
-- USER PROMPTS
07
-- IMAGE
08
set thereplacementImageFileto ¬
09
(choose fileof type "public.image" default location ¬
10
(path topictures folder) with prompt "Choose the image file of the item to sell:")
11
12
-- ITEM KIND
13
repeat
14
display dialog "Enter a single word describing the kind of item to be sold:" default answer "Object"
Mention of third-party websites and products is for informational purposes only and constitutes neither an endorsement nor a recommendation. MACOSXAUTOMATION.COM assumes no responsibility with regard to the selection, performance or use of information or products found at third-party websites. MACOSXAUTOMATION.COM provides this only as a convenience to our users. MACOSXAUTOMATION.COM has not tested the information found on these sites and makes no representations regarding its accuracy or reliability. There are risks inherent in the use of any information or products found on the Internet, and MACOSXAUTOMATION.COM assumes no responsibility in this regard. Please understand that a third-party site is independent from MACOSXAUTOMATION.COM and that MACOSXAUTOMATION.COM has no control over the content on that website. Please contact the vendor for additional information.