Create table in Pages with query as to number of col and lines

The process of creating tables in Pages is quite click intensive.
I would like to create a macro which would:

  • open Pages document (simple)
  • set the font type and size (a script for which is provided in the forum)
  • ask me how many columns and lines
  • create a corresponding Pages table
    I have no clue how to create actions for the latter two
    thanks very much in advance


I think you probably will need AppleScript to do this. The AppleScript could then be called by a KM macro.

Here’s an example Pages AppleScript from

tell application "Pages"
    set myDoc to make new document
    tell page 1 of myDoc to set myTable to make new table with properties {column count:4, row count:12}
    tell cell range of myTable
        set width of columns to 120
        set text wrap to true
        set alignment to center

        -- to set value of the headers and some cells
        set j to 1
        repeat with i in {"Column1", "Column2", "Column3", "Column4", "data cell 1", "data cell 2", "hello", "data cell 4", "moredata", "moredata", "data", "hello"}
            set value of cell j to i
            set j to j + 1
        end repeat
    end tell
end tell

To see the other commands and properties of Pages that can be used with AppleScript, open the Pages Dictionary from the Script Editor.

For more info, see AppleScript and Pages

1 Like

thank you for your answer.
I am a bit confused. As far as I can guess from reading the script:
1- the end result is to specifically create the table below
2- there is no user interface / query asking the number of rows and columns
3- the cells are filled up with useless info (hello, data, etc)

How do you create an answer with one or multiple quotes? It's very elegant.

I did more reading based on your references.
I think that the easiest approach is to simply create the table in Numbers (much easier than Pages), and when finished copy paste into a new Pages document.
Once the table is created, it is very click intensive to specify all of the following. Could it be done with KBM+Apple Script?
basically one would highlight the table and run the macro to format it.


AFAIK, KM does NOT have any Pages or Numbers specific actions, so you will need to do the following:

  1. Write an AppleScript that formats the table, and then call that script from KM macro
  2. Use the KM Select or Show Menu Item Action, combined with Press a Button actions.

I think #1 would be the most reliable and capable.

I don’t have the Pages app, and have never used it, so I can’t offer any help for using AppleScript with Pages (or Numbers), but there are many examples on the Internet.

1 Like

Thank you. I understand that you don't use Numbers. I am asking this question in general terms,
Why does the following macro not work. It should center the word testing.

Since I don't have Numbers, I can't test your macro, or even do a manual walk-through. Try starting the debugger (KM Status menu > Start Debugging, and then run your macro, Observe what happens step by step.

1 Like

dubugging function: that’s exactly what I was looking for. thanks !

Sorry; I am confused. I start the debugger and the macro, and then what do I do? The macro seems to be working in the background.


1 Like