mingsai

Numbers New Document with Sheet for every month

Feb 22nd, 2014
136
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. set the monthNames to {"January", "February", "March", "April", "May", "June", "July", "August", "September", "October", "November", "December"}
  2. set thisYearName to (year of (current date)) as string
  3.  
  4. tell application "Numbers"
  5.     activate
  6.     -- confirmation dialog
  7.     display dialog "This script will create a new document containing a sheet, " & ¬
  8.         "with a named table, for every month of the year." buttons ¬
  9.         {"Cancel", "Continue"} default button 2 with icon 1
  10.     -- make a new document
  11.     set thisDocument to make new document
  12.     -- create a sheet with a named table for every month
  13.     tell thisDocument
  14.         repeat with i from 1 to the count of the monthNames
  15.             set thisMonthName to item i of the monthNames
  16.             set thisTableName to thisMonthName & "-" & thisYearName
  17.             if i is 1 then
  18.                 -- name the sheet
  19.                 set the name of sheet 1 to thisMonthName
  20.                 tell sheet 1
  21.                     -- delete default table and create new one
  22.                     delete every table
  23.                     make new table with properties {name:thisTableName}
  24.                 end tell
  25.             else
  26.                 -- make a new sheet
  27.                 set thisSheet to ¬
  28.                     make new sheet with properties {name:thisMonthName}
  29.                 tell thisSheet
  30.                     -- delete default table and create new one
  31.                     delete every table
  32.                     make new table with properties {name:thisTableName}
  33.                 end tell
  34.             end if
  35.         end repeat
  36.         delay 0.5
  37.         -- display the first sheet by selecting table on current sheet, then table on first sheet
  38.         set selection range of table 1 of sheet 12 to cell range of table 1 of sheet 12
  39.         delay 1
  40.         set selection range of table 1 of sheet 1 to cell range of table 1 of sheet 1
  41.     end tell
  42.     display dialog "Document created." buttons {"OK"} default button 1 with icon 1
  43. end tell
Advertisement
Add Comment
Please, Sign In to add comment