Row Lines with Gutters
Open in Script Editor
01 property defaultVerticalMargin : 36
02 property defaultHorizontalMargin : 36
03 property defaultgutterHeight : 12
04 property defaultrowCount : 6
05
06 tell application "Pages"
07 activate
08
09 set chosenPageSize to (choose from list {"Cancel", "A3", "A4", "A5", "B5", "US Letter", "US Legal", "Tabloid"} with prompt "Pick the page size:")
10 if chosenPageSize is false then error number -128
11 set chosenPageSize to chosenPageSize as string
12 if chosenPageSize is "A4" then
13 set thisPageDimensions to {595, 842}
14 else if chosenPageSize is "A3" then
15 set thisPageDimensions to {842, 1191}
16 else if chosenPageSize is "A5" then
17 set thisPageDimensions to {420, 595}
18 else if chosenPageSize is "B5" then
19 set thisPageDimensions to {499, 709}
20 else if chosenPageSize is "US Letter" then
21 set thisPageDimensions to {612, 792}
22 else if chosenPageSize is "US Legal" then
23 set thisPageDimensions to {612, 1008}
24 else if chosenPageSize is "Tabloid" then
25 set thisPageDimensions to {792, 1224}
26 end if
27 copy thisPageDimensions to {documentWidth , documentHeight }
28
29 set thisPrompt to "Enter the top margin height in pixels:"
30 set verticalTopMarginHeight to my promptForIntegerValue (thisPrompt , 0, documentHeight div 2, defaultVerticalMargin )
31
32 set thisPrompt to "Enter the bottom margin height in pixels:"
33 set verticalBottomMarginHeight to my promptForIntegerValue (thisPrompt , 0, documentHeight div 2, defaultVerticalMargin )
34
35 set thisPrompt to "Enter the left margin width in pixels:"
36 set sideLeftMarginWidth to my promptForIntegerValue (thisPrompt , 0, documentHeight div 2, defaultHorizontalMargin )
37
38 set thisPrompt to "Enter the right margin width in pixels:"
39 set sideRightMarginWidth to my promptForIntegerValue (thisPrompt , 0, documentHeight div 2, defaultHorizontalMargin )
40
41 set thisPrompt to "Enter the gutter height in pixels:"
42 set gutterHeight to my promptForIntegerValue (thisPrompt , 0, 200, defaultgutterHeight )
43
44 set thisPrompt to "Enter the row count:"
45 set rowCount to my promptForIntegerValue (thisPrompt , 2, 50, defaultrowCount )
46
47 set gutterCount to rowCount - 1
48
49 set editableAreaHeight to documentHeight - verticalTopMarginHeight - verticalBottomMarginHeight
50
51 set editableRowAreaHeight to editableAreaHeight - (gutterCount * gutterHeight )
52
53 set editableSegmentHeight to editableRowAreaHeight div rowCount
54
55 tell document 1
56 tell current page
57 set startPointHorizontal to sideLeftMarginWidth
58 set endPointHorizontal to documentWidth - sideRightMarginWidth
59
60 set thisStartPointVertical to verticalTopMarginHeight
61 set thisEndPointVertical to verticalTopMarginHeight
62
63 set repeatCount to rowCount + 1
64 repeat with i from 1 to the repeatCount
65
66 set newLine to make new line
67 tell newLine
68 set start point to {startPointHorizontal , thisStartPointVertical }
69 set end point to {endPointHorizontal , thisEndPointVertical }
70 set locked to true
71 end tell
72
73 if i is not 1 and i is not repeatCount then
74
75 set thisStartPointVertical to thisStartPointVertical + gutterHeight
76 set thisEndPointVertical to thisEndPointVertical + gutterHeight
77 set newLine to make new line
78 tell newLine
79 set start point to {startPointHorizontal , thisStartPointVertical }
80 set end point to {endPointHorizontal , thisEndPointVertical }
81 set locked to true
82 end tell
83
84 set thisStartPointVertical to thisStartPointVertical + editableSegmentHeight
85 set thisEndPointVertical to thisEndPointVertical + editableSegmentHeight
86 else
87
88 set thisStartPointVertical to thisStartPointVertical + editableSegmentHeight
89 set thisEndPointVertical to thisEndPointVertical + editableSegmentHeight
90 end if
91 end repeat
92 end tell
93 end tell
94 end tell
95
96 on promptForIntegerValue (thisPrompt , minimumValue , maximumValue , defaultValue )
97 tell application "Pages"
98 repeat
99 display dialog thisPrompt default answer (defaultValue as string )
100 try
101 set thisValue to (the text returned of the result ) as integer
102 if thisValue is greater than or equal to minimumValue and thisValue is less than or equal to maximumValue then
103 return thisValue
104 end if
105 on error
106 beep
107 end try
108 end repeat
109 end tell
110 end promptForIntegerValue