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