Copy text from Pages with multiple text boxes?

I'm a fairly casual Pages user, having spent a lifetime in MSWord and only recently switched over.


My question is about copying and pasting sections of text from pages to something else, like say the body of a Mac Mail message.


If it's text from a single text box, thats fairly straightforward, but I often have documents that are multiple sections, each its own text box. How do I select the text from several inline text boxes? Basic copy does not seem to work, and this is a fairly common need I have. If this is impossible, then I have to rethink how I make my documents. My stupid workaround is to save my documents as a pdf and then open and copy the text from the pdf but that seems ridiculous.


any advice or links to appropriate articles are welcome. thanks.



Mac Studio, macOS 14.0

Posted on Oct 19, 2023 9:33 AM

Reply
2 replies

Oct 19, 2023 10:04 AM in response to Javier Bonafont

Its not going to happen. Pages cannot select non-contiguous text whether in body text or as entered in separate Text boxes. But, you can tell AppleScript to get every text box in the open document, and in turn, the text within each Text box that is appended to a single text string with returns between Text box content.


The AppleScript will create a list of these Text boxes ordered from last to first and that needs to be reversed to show the Text box text in order of appearance in the document.


Copy/paste the following into Apple's Script Editor, click the hammer icon to compile it and with an open Pages document containing your Text boxes, click Run. A dialog will appear with the extracted text from each Text box separated by two returns. You copy/paste the content from that dialog into the Mail compose window.


use scripting additions

property textContent : ""

tell application "Pages"
	tell front document
		
		set TBList to (its every text item)
		tell application "Finder" to set rTBList to reverse of TBList
		repeat with atb in rTBList
			set textContent to textContent & atb's object text & return & return
		end repeat
		
	end tell
end tell
display dialog textContent
return


Oct 20, 2023 6:34 AM in response to VikingOSX

When I ran the same code again today ( 2023-10-20), the order was actually backwards from my previous test, so the revised code is:


use scripting additions

property textContent : ""

tell application "Pages"
	tell front document
		
		set TBList to (its every text item)
		if TBList = {} then return -- no Text boxes found
		
		repeat with atb in TBList
			set textContent to textContent & atb's object text & return & return
		end repeat
		
	end tell
end tell
display dialog textContent with title "Pages Text Box Contents"

return


As an addendum and proof that this code works, here are three unlinked Pages v13.2 Text Boxes:



And the contents presented in a dialog box for copy/paste opportunity:


Copy text from Pages with multiple text boxes?

Welcome to Apple Support Community
A forum where Apple customers help each other with their products. Get started with your Apple ID.