Numbers Spreadsheet to Pages Film Script

I have a sheet in Numbers.app which contains:

  • Column A scene no
  • B character names
  • C location
  • D time
  • E interior or exterior
  • F has the brief of the scene

What I need is to send all this data automatically to a Pages document in a form of a film script.

Incredibly off the topic of this thread, but happy to help.

@Ahmed_Adel - what I think you are looking to do is not an applescript issue. The menu command in Sheets is called “Transpose Rows and Columns” in the Table Menu.

If you look at the screen shot below. I am assuming you’ve created a document similar to this:

If you simply Transpose the Rows to Columns, then you will get a clean way to copy and paste:

And it will look more like this:

Now, you can build a simple template in Pages that has the Table Columns on one side, and the blank rows on the right.
Then, you can just copy paste in the items.


If you could provide an example of what the source document looks like in numbers and how you want the destination document in pages to look that would be helpful.

I am guessing that your Numbers sheet looks something like this:

You can read a Numbers table row by row. Then, you can figure out whether you’re looking at a “Character” line (with dialog in the last column) or a “Scene Number” line (without a character). Then, you can take what you find in a row and add it to the end of a Pages document.

I am making some guesses about how your Numbers sheet looks, and how you want your Pages document to look, so you may need to adjust things. But, I think the basic script here will help you.

tell application "Numbers"
   set mydocument to document 1 -- get the frontmost document
   tell mydocument
      set mySheet to active sheet
      set myTable to table 1 of mySheet
      set theRows to every row of myTable
      set theRows to rows 2 thru (count of theRows) of myTable -- we get every row except the first one.
      repeat with aRow in theRows
         set theItems to (formatted value of cells of aRow) as list
         set theSceneNo to item 1 of theItems
         set theCharacterName to item 2 of theItems
         set theLocation to item 3 of theItems
         set theTime to item 4 of theItems
         set theInteriorOrExterior to item 5 of theItems
         set theDescription to item 6 of theItems
         if theItems is not {missing value, missing value, missing value, missing value, missing value, missing value} then
            my WriteToPages(theItems)
         end if
      end repeat
   end tell
end tell

on WriteToPages(someItems)
   if item 2 of someItems is missing value then -- theCharacter is empty, so this is a "scene" line
      tell application "Pages"
         tell document 1
            set body text to body text & return & return & ¬
               item 1 of someItems & tab & item 5 of someItems & tab & item 3 of someItems & tab & item 4 of someItems
         end tell
      end tell
   else
      tell application "Pages"
         tell document 1
            set body text to body text & return & return & ¬
               item 2 of someItems & return & item 6 of someItems
         end tell
      end tell
   end if
end WriteToPages

You don’t need to go through the steps that say “theSceneNo is item 1 of theItems” etc. but it’s a way for you to know what I’m doing in the script and also to check things (you could return “item 1 of theItems” to see the scene number).

The result of this script looks like this:

image

I did open a new Pages document ahead of time, before running the script. Obviously this could be in the script itself, as could a lot of other nice touches. But this is a good start.