Friday, January 19, 2018

#1 2018-01-11 03:57:11 am

annrek
Member
Registered: 2018-01-09
Posts: 2

pages - text placeholder

Hello

I have a simple script that works on an open iwork file
allowing you to insert your own texts in the place of replacement text
(placeholder text). The action can be performed only once - after swapping
I already have plain text - so I can not go wrong or do it again ...
I need to modify the script so that after inserting my own texts instead of replacement text, the changed texts are still marked as placeholder text so that I can re-apply the script in the same document ...
basically, I do not know much about the Apple script, so any help will be appreciated.

thank you in advance
Marcin

Applescript:

tell application "Pages"
   activate
   
   if not (exists document 1) then error number -128
   tell document 1
       
       -- GET ALL TAGS
       set theseTags to the tag of every placeholder text
       
       -- FILTER FOR UNIQUE TAGS
       set uniqueTags to {}
       repeat with i from 1 to the count of theseTags
           set thisTag to item i of theseTags
           if thisTag is not in uniqueTags then
               set the end of uniqueTags to thisTag
           end if
       end repeat
       
       -- PROMPT USER FOR REPLACEMENT TEXT
       repeat with i from 1 to the count of uniqueTags
           set thisTag to item i of uniqueTags
           display dialog "Enter the replacement text for this tag:" & ¬
               return & return & thisTag default answer "" buttons ¬
               {"Cancel", "Skip", "OK"} default button 3
           copy the result to {button returned:buttonPressed, text returned:replacementString}
           if buttonPressed is "OK" then
               set (every placeholder text whose tag is thisTag) to replacementString
           end if
       end repeat
   end tell
end tell

Offline

 

#2 2018-01-11 05:02:18 pm

Nigel Garvey
Moderator
From:: Warwickshire, England
Registered: 2002-11-20
Posts: 4488

Re: pages - text placeholder

Hi Marcin. Welcome to MacScripter.

I may be wrong, but I don't think that what you want can sensibly be done by script in Pages. As far as I can see, when placeholder text is changed, it stops being placeholder text. The only way to make it text placeholder text again is either to undo the change or to select the changed text manually and use the appropriate keystroke or Advanced option in the Format menu. The keystroke or menu item would be fairly easy to do with GUI scripting, but I can't see any way to select the text.  hmm


NG

Offline

 

#3 2018-01-12 08:35:36 am

annrek
Member
Registered: 2018-01-09
Posts: 2

Re: pages - text placeholder

Hello

as you write - after changing the replacement text it ceases to be a substitute text, but it is important that the script re-formatted it as a substitute after inserting the text. Maybe this is wrong reasoning, but if you can change the text format to bold, italic, etc., can not it be changed to "placeholder text"? In the script you would have to find the command "place text instead of placeholder text format as placeholder text";)

Offline

 

Board footer

Powered by FluxBB

RSS (new topics) RSS (active topics)