Submit Hint Search The Forums LinksStatsPollsHeadlinesRSS
14,000 hints and counting!

Make items/months tables in Numbers '09 via AppleScript Apps
The following AppleScript will create a new sheet in Numbers '09 that contains the month names going horizontally or vertically (at your choice), and then populate the opposite axis with some number of Item nn headings, where nn ranges from one to the number of entries you specify at runtime.
property month_names : {"January", "February", "March", "April", "May", "June", "July", "August", "September", "October", "November", "December"}

tell application "Numbers"
    activate
    
    if not (exists document 1) then
        display dialog "There is no document open." buttons {"Cancel"} default button 1
    end if
    
    repeat
        display dialog "Enter the number of items to track and choose the orientation of the month names:" default answer "6" buttons {"Cancel", "Left Column", "Top Row"} default button 1
        copy the result to {button returned:month_orientation, text returned:item_count}
        try
            set the item_count to item_count as integer
            if the item_count is greater than 0 then exit repeat
        on error
            beep
        end try
    end repeat
    
    tell document 1
        tell sheet 1
            
            if the month_orientation is "Top Row" then
                set this_table to make new table with properties {name:"MONTHS", column count:13, row count:(item_count + 1)}
                tell table "MONTHS"
                    -- set any global cell properties
                    set the height of every row to 24
                    set the vertical alignment of every row to center
                    set the alignment of every row to center
                    tell row 1
                        -- set specific properties for the title row
                        set the vertical alignment to center
                        set the alignment to center
                        -- insert labels
                        repeat with i from 2 to 13
                            set value of cell i to item (i - 1) of the month_names
                        end repeat
                    end tell
                    tell column 1
                        -- set specific properties for the title column
                        set the vertical alignment to center
                        set the alignment to center
                        -- insert labels
                        repeat with i from 2 to item_count + 1
                            set value of cell i to "Item " & (i - 1 as string)
                        end repeat
                    end tell
                end tell
            else if the month_orientation is "Left Column" then
                set this_table to make new table with properties {name:"MONTHS", column count:(item_count + 1), row count:13}
                tell table "MONTHS"
                    -- set any global cell properties
                    set the height of every row to 24
                    set the vertical alignment of every row to center
                    set the alignment of every row to center
                    tell column 1
                        -- set specific properties for the title column
                        set the vertical alignment to center
                        set the alignment to center
                        -- insert labels
                        repeat with i from 2 to 13
                            set value of cell i to item (i - 1) of the month_names
                        end repeat
                    end tell
                    tell row 1
                        -- set specific properties for the title row
                        set the vertical alignment to center
                        set the alignment to center
                        -- insert labels
                        repeat with i from 2 to item_count + 1
                            set value of cell i to "Item " & (i - 1 as string)
                        end repeat
                    end tell
                end tell
                
            end if
        end tell
    end tell
end tell
Save the script as a script file (.scpt) from Script Editor, and put it in Home » Library » Scripts » Applications » Numbers to have them appear in the Scripts Menu while Numbers is the frontmost application. Then just activate the script when needed, set the number of Item entries you'd like it to create, and then specify either the left column (vertical) or top row (horizontal) for the month names, and you're done.

[robg adds: This worked as described in my testing.]
    •    
  • Currently 1.71 / 5
  You rated: 3 / 5 (7 votes cast)
 
[9,302 views]  

Make items/months tables in Numbers '09 via AppleScript | 2 comments | Create New Account
Click here to return to the 'Make items/months tables in Numbers '09 via AppleScript' hint
The following comments are owned by whoever posted them. This site is not responsible for what they say.
Make items/months tables in Numbers '09 via AppleScript
Authored by: ianeiloart on Feb 15, '09 12:23:21PM

Or, type "January" in one cell, and drag the corner of the cell. Months through to December are completed automatically. Similarly, type "item 1" in a cell, and drag the corner to have "item 2", "item 3", etc autofilled.

---
Ian Eiloart



[ Reply to This | # ]
Make items/months tables in Numbers '09 via AppleScript
Authored by: NachoJ on May 01, '10 01:58:03PM
I'd been learnig a lot with this kind of script examples. Now I want to write a script that allow the user to choose a cell or a range of cells in Numbers and do something with them. I search a lot and find nothing. To be more specific, I want to do something similar to what you can do in Excel using the "Data/Table..." menu. I will appreciate any help. Thanks. Ignacio

[ Reply to This | # ]