newbi coding keystrokes in iWork Pages

I am trying to take a list in Pages, format it using an applescript which I can then convert over to Numbers. Each Pages document is a different length with each line needing formatting. For example I have a list that looks like this:

line 1
line 2
line 3
line 4
line 5
line 6

And I need to format it to look like this:

Line 1 (tab) Line 2 (tab) Line 3 (tab) line 4
Line 5 (tab Line 6 (tab) etc…

I think I could do it using keystrokes but am not having any luck with this. Any idea’s?

Hi. No need to use keystrokes. Select the text in Pages and try this…

set lineSeparatorCharacter to character id 8232 -- this character separates lines in Pages
set tabCharacter to character id 9 -- a tab character

-- get the selected text from Pages
tell application "Pages"
	set theText to contents of selection
end tell

-- replace the line separator character with the tab character
set text item delimiters to lineSeparatorCharacter
set textList to text items of theText
set text item delimiters to tabCharacter
set newText to textList as text
set text item delimiters to ""

-- put the new text back into the selection is Pages
tell application "Pages"
	set selection to newText
end tell

Hi mglmusic and regulus6633,

This is my first day looking at this forum. I don’t know anything about AppleScript, but am curious. I have Pages, so I copied mglmusic’s line 1-6 into a new Pages document. Regulus6633, I opened the AppleScript Editor and your script is in it. I highlighted the Pages text like you said to do, then I clicked on Run in the script editor, but nothing happened. How do I get your script to work in Pages?

It should work in Pages. It will get the text you have selected, tab separate it as you requested, and put the changed text back into the selection in Pages. So your highlighted text should change (you need to select several lines for it to do anything). If it did nothing then you’ll need to modify the applescript code to make it work for you. It works for me. It should at least give you an idea about how to make a script to perform your task.