Make items/months tables in Numbers '09 via AppleScript
Feb 13, '09 07:30:00AM • Contributed by: mr. applescript
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.]