Grid-based design is a standard format of page layout used for documents that display numerous individualized items, such as catalogs.
Here’s a script that can quickly create a grid of page items (text boxes and/or shapes), and even insert default text into the created items.
Create Grid of Page Items
Open in Script Editor
01 property defaulttopMarginHeight : 36
02 property defaultbottomMarginHeight : 36
03
04 property defaultleftMarginWidth : 36
05 property defaultrightMarginWidth : 36
06
07 property defaultcolumnGutterWidth : 12
08 property defaultrowGutterHeight : 12
09 property defaultcolumnCount : 3
10 property defaultrowCount : 6
11
12 tell application "Pages"
13 activate
14
15 set chosenPageSize to (choose from list {"Cancel", "A3", "A4", "A5", "B5", "US Letter", "US Legal", "Tabloid"} with prompt "Pick the page size:")
16 if chosenPageSize is false then error number -128
17 set chosenPageSize to chosenPageSize as string
18 if chosenPageSize is "A4" then
19 set thisPageDimensions to {595, 842}
20 else if chosenPageSize is "A3" then
21 set thisPageDimensions to {842, 1191}
22 else if chosenPageSize is "A5" then
23 set thisPageDimensions to {420, 595}
24 else if chosenPageSize is "B5" then
25 set thisPageDimensions to {499, 709}
26 else if chosenPageSize is "US Letter" then
27 set thisPageDimensions to {612, 792}
28 else if chosenPageSize is "US Legal" then
29 set thisPageDimensions to {612, 1008}
30 else if chosenPageSize is "Tabloid" then
31 set thisPageDimensions to {792, 1224}
32 end if
33 copy thisPageDimensions to {documentWidth , documentHeight }
34
35 set thisPrompt to "Enter the top margin height in pixels:"
36 set topMarginHeight to my promptForIntegerValue (thisPrompt , 0, documentHeight div 2, defaulttopMarginHeight )
37
38 set thisPrompt to "Enter the bottom margin height in pixels:"
39 set bottomMarginHeight to my promptForIntegerValue (thisPrompt , 0, documentHeight div 2, defaultbottomMarginHeight )
40
41 set thisPrompt to "Enter the left margin width in pixels:"
42 set leftMarginWidth to my promptForIntegerValue (thisPrompt , 0, documentHeight div 2, defaultleftMarginWidth )
43
44 set thisPrompt to "Enter the right margin width in pixels:"
45 set rightMarginWidth to my promptForIntegerValue (thisPrompt , 0, documentHeight div 2, defaultrightMarginWidth )
46
47 set thisPrompt to "Enter the column gutter width in pixels:"
48 set columnGutterWidth to my promptForIntegerValue (thisPrompt , 0, 200, defaultcolumnGutterWidth )
49
50 set thisPrompt to "Enter the row gutter height in pixels:"
51 set rowGutterHeight to my promptForIntegerValue (thisPrompt , 0, 200, defaultrowGutterHeight )
52
53 set thisPrompt to "Enter the column count:"
54 set columnCount to my promptForIntegerValue (thisPrompt , 2, 50, defaultcolumnCount )
55
56 set thisPrompt to "Enter the row count:"
57 set rowCount to my promptForIntegerValue (thisPrompt , 2, 50, defaultrowCount )
58
59 display dialog "Do you want to create Shapes or Text Items?" buttons {"Alternate", "Shapes", "Text Items"}
60 set the objectType to the button returned of the result
61
62 display dialog "Do you want default text added to the page items?" buttons {"Cancel", "No", "Yes"} default button 1
63 set shouldAddText to the button returned of the result
64
65 set columnGutterCount to columnCount - 1
66 set rowGutterCount to rowCount - 1
67
68 set editableAreaWidth to documentWidth - leftMarginWidth - rightMarginWidth
69 set editableAreaHeight to documentHeight - topMarginHeight - bottomMarginHeight
70
71 set editableColumnAreaWidth to editableAreaWidth - (columnGutterCount * columnGutterWidth )
72 set editableRowAreaHeight to editableAreaHeight - (rowGutterCount * rowGutterHeight )
73
74 set shapeWidth to editableColumnAreaWidth div columnCount
75 set shapeHeight to editableRowAreaHeight div rowCount
76
77 tell document 1
78 tell current page
79 set thisHorizontalOffset to leftMarginWidth
80 set thisVerticalOffset to topMarginHeight
81 repeat with i from 1 to rowCount
82 repeat with q from 1 to columnCount
83 if shouldAddText is "Yes" then
84 set placeholderText to ("PLACEHOLDER-" & (i as string ) & "-" & (q as string ))
85 else
86 set placeholderText to ""
87 end if
88 if the objectType is "Shapes" then
89 make new shape with properties {width :shapeWidth , height :shapeHeight , position :{thisHorizontalOffset , thisVerticalOffset }, object text :placeholderText }
90 else if the objectType is "Text Items" then
91 make new text item with properties {width :shapeWidth , height :shapeHeight , position :{thisHorizontalOffset , thisVerticalOffset }, object text :placeholderText }
92 else if the objectType is "Alternate" then
93 if i mod 2 is 0 then
94 make new text item with properties {width:shapeWidth , height :shapeHeight , position :{thisHorizontalOffset , thisVerticalOffset }, object text :placeholderText }
95 else
96 make new shape with properties {width:shapeWidth , height :shapeHeight , position :{thisHorizontalOffset , thisVerticalOffset }, object text :placeholderText }
97 end if
98 end if
99 set thisHorizontalOffset to thisHorizontalOffset + columnGutterWidth + shapeWidth
100 end repeat
101 set thisHorizontalOffset to leftMarginWidth
102 set thisVerticalOffset to thisVerticalOffset + rowGutterHeight + shapeHeight
103 end repeat
104 end tell
105 end tell
106 end tell
107
108 on promptForIntegerValue (thisPrompt , minimumValue , maximumValue , defaultValue )
109 tell application "Pages"
110 repeat
111 display dialog thisPrompt default answer (defaultValue as string )
112 try
113 set thisValue to (the text returned of the result ) as integer
114 if thisValue is greater than or equal to minimumValue and thisValue is less than or equal to maximumValue then
115 return thisValue
116 end if
117 on error
118 beep
119 end try
120 end repeat
121 end tell
122 end promptForIntegerValue