The geometry is all askew, but this should give you something to work from:
use framework "Carbon" -- AEInteractWithUser() is in Carbon
use AppleScript version "2.4"
use framework "Foundation"
use framework "AppKit"
use script "Myriad Tables Lib" version "1.0.7"
use scripting additions
property NSTextField : a reference to current application's NSTextField
property NSLeftTextAlignment : a reference to 0
property NSNoTitle : a reference to 0
property NSRegularControlSize : a reference to 0
property NSCenterTextAlignment : a reference to 2
property NSPathStylePopUp : a reference to 2
property NSRightTextAlignment : a reference to 1
property defaultRows : {1, 2}
property checkState : 1
property theCheckbox : missing value
property thePopup : missing value
property handlerResult : missing value
property theAccessoryView : missing value
property emailList : {{}}
set popupList to {}
set myDate to (current date)
repeat with x from 1 to 5
set myDate to myDate + 1 * days
set the end of popupList to date string of myDate
end repeat
set defaultDate to item 1 of popupList
set tablePrompt to "Select the date, email addresses and indicate if there are ads on the page"
set selectedRows to {1, 2}
set {enteredText, placeHolder, theLeft, theBottom, theWidth, extraHeight, acceptsTabs} to ¬
{"Label Entry Text", "Placeholder Text", 10, 10, 17, 10, true}
set {labelString, theLeft, theBottom, maxWidth, alignment, wrapsBool, controlSize, boldType} to ¬
{"labelString", 0, 0, 50, "right", true, 12, true}
repeat
if current application's NSThread's isMainThread() as boolean then
my createCheckBoxMainThread:{"Page has other editorial", "checkboxClicked:", checkState}
my createPopupMainThread:{popupList, defaultDate}
my createFieldMainThread:{enteredText, placeHolder, theLeft, theBottom, theWidth, extraHeight, acceptsTabs}
set {theField, theBottom} to handlerResult
my createLabelMainThread:{labelString, theLeft, theBottom, maxWidth, alignment, wrapsBool, controlSize, boldType}
set {theLabel, theBottom, newWidth} to handlerResult
my buildAccessoryViewMainThread:{theLabel, theField, theCheckbox, thePopup}
else
my performSelectorOnMainThread:"createCheckBoxMainThread:" withObject:{"Page has other editorial", "checkboxClicked:", checkState} waitUntilDone:true
my performSelectorOnMainThread:"createPopupMainThread:" withObject:{popupList, defaultDate} waitUntilDone:true
my performSelectorOnMainThread:"createFieldMainThread:" withObject:{enteredText, placeHolder, theLeft, theBottom, theWidth, extraHeight, acceptsTabs} waitUntilDone:true
set {theField, theBottom} to handlerResult
my performSelectorOnMainThread:"createLabelMainThread:" withObject:{labelString, theLeft, theBottom, maxWidth, alignment, wrapsBool, controlSize, boldType} waitUntilDone:true
set {theLabel, theBottom, newWidth} to handlerResult
my performSelectorOnMainThread:"buildAccessoryViewMainThread:" withObject:{theLabel, theField, theCheckbox, thePopup} waitUntilDone:true
end if
set theTable to make new table with data emailList ¬
with title ¬
"TV Highlights and grid pages" with prompt tablePrompt ¬
multiple selections allowed true ¬
can add and delete true ¬
editable columns {1, 2} ¬
column headings {"Label", "Address"} ¬
row numbering false ¬
initially selected rows selectedRows ¬
without empty selection allowed
modify table theTable ¬
OK button name ¬
"Okay" cancel button name ¬
"Cancel" extra button name ¬
"Refresh" highlighted rows {} ¬
alternate backgrounds false ¬
row dragging false ¬
without column reordering
modify table theTable accessory view theAccessoryView
set theAccessoryView to missing value -- to avoid error messages when saving
set tableResult to display table theTable ¬
with extended results
set selectedRows to rows selected of tableResult
set buttonClicked to button number of tableResult
set emailAddresses to values selected of tableResult
log emailAddresses
set finalPosition to final position of tableResult
set fullList to values returned of tableResult
set otherEdOnPage to theCheckbox's state() as boolean
if otherEdOnPage then
set checkState to 1
else
set checkState to 0
end if
set theCheckbox to missing value -- to avoid error messages when saving
set pubDate to thePopup's title() as text
set thePopup to missing value
if buttonClicked is 1 then --OK
set confirmationPrompt to {"Please confirm notification:", ""}
set displayAddresses to my stripNamesFromAddresses(emailAddresses)
set AppleScript's text item delimiters to {", "}
set displayAddresses to displayAddresses as text
set the end of confirmationPrompt to "Send to: " & displayAddresses
set confirmationtext to {"The TV grid and highlights page for " & pubDate & " is ready for print. ", ""}
if otherEdOnPage then
set the end of confirmationtext to "The page has other editorial so I won't release."
else
set the end of confirmationtext to "I can release when OK'd."
end if
set AppleScript's text item delimiters to {return}
set userResponse to display dialog confirmationPrompt as text ¬
default answer confirmationtext as text ¬
buttons {"Cancel", "Refresh", "Confirm"} ¬
default button 3 ¬
with title ¬
"Email Confirmation" giving up after 60
if the button returned of userResponse is "Confirm" then
set emailText to text returned of userResponse
exit repeat
else
if the button returned of userResponse is "Refresh" then
set confirmationtext to {"The TV grid and highlights page for " & pubDate & " is ready for print. ", ""}
if otherEdOnPage then
set the end of confirmationtext to "The page has other editorial so I won't release."
else
set the end of confirmationtext to "I can release when OK'd."
end if
set tablePrompt to (confirmationPrompt as text) & return & return & confirmationtext as text
end if
end if
else if buttonClicked is 3 then
return
end if
end repeat
on stripNamesFromAddresses(emailAddresses)
log emailAddresses
set newAddressList to {}
set saveTID to AppleScript's text item delimiters
set AppleScript's text item delimiters to {": "}
repeat with thisAddress in emailAddresses
set the end of newAddressList to item 2 of thisAddress as text
log newAddressList
end repeat
set AppleScript's text item delimiters to saveTID
return newAddressList
end stripNamesFromAddresses
on createCheckBoxMainThread:theArg
set {theTitle, theAction, theDefault} to theArg as list
-- build a checkbox
set my theCheckbox to current application's NSButton's alloc()'s initWithFrame:{{10, 10}, {320, 20}}
tell theCheckbox
its setButtonType:(current application's NSSwitchButton)
its setTitle:theTitle
its setTarget:me
-- its setAction:theAction -- a handler in this script
its setState:theDefault
end tell
end createCheckBoxMainThread:
on createPopupMainThread:theArg
set {entryList, defaultValue} to theArg as list
set my thePopup to current application's NSPopUpButton's alloc()'s initWithFrame:{{10, 30}, {300, 35}} pullsDown:false
thePopup's addItemsWithTitles:entryList
thePopup's selectItemWithTitle:defaultValue
end createPopupMainThread:
on buildAccessoryViewMainThread:theControls
set my theAccessoryView to current application's NSView's alloc()'s initWithFrame:{{0, 0}, {320, 60}}
repeat with aControl in theControls
(theAccessoryView's addSubview:aControl)
end repeat
end buildAccessoryViewMainThread:
on createFieldMainThread:theArg
set {enteredText, placeHolder, theLeft, theBottom, theWidth, extraHeight, acceptsTabs} to theArg as list
set theTop to theBottom + 22 + extraHeight
set theField to (NSTextField's alloc()'s initWithFrame:{{theLeft, theBottom}, {theWidth, theTop - theBottom}})
tell theField
(its setEditable:true)
(its setBezeled:true)
its (cell()'s setPlaceholderString:placeHolder)
if extraHeight > 0 then its (cell()'s setWraps:true)
its setStringValue:enteredText
if acceptsTabs then its setDelegate:me
end tell
-- return theField, the top of the field
set my handlerResult to {theField, theTop}
end createFieldMainThread:
on createLabelMainThread:theArg
set {labelString, theLeft, theBottom, maxWidth, alignment, wrapsBool, controlSize, boldType} to theArg as list
-- create label, set size and make font
set theLabel to (NSTextField's alloc()'s initWithFrame:{{theLeft, theBottom}, {maxWidth, 17}})
-- format label
if alignment begins with "r" then
theLabel's setAlignment:NSRightTextAlignment
else if alignment begins with "c" then
theLabel's setAlignment:NSCenterTextAlignment
else
theLabel's setAlignment:NSLeftTextAlignment
end if
tell theLabel
its setPreferredMaxLayoutWidth:maxWidth
(its setStringValue:labelString)
(its setEditable:false)
(its setSelectable:true)
(its setBordered:false)
(its setDrawsBackground:false)
its (cell()'s setWraps:wrapsBool)
end tell
-- size label
theLabel's setFrameSize:(theLabel's fittingSize())
-- set alignment
set theFrame to theLabel's frame()
if class of theFrame is record then
set {width:newWidth, height:theHeight} to theFrame's |size|
else
set {newWidth, theHeight} to item 2 of theFrame
end if
if alignment begins with "r" then
set theOrigin to {theLeft + maxWidth - newWidth, theBottom}
else if alignment begins with "c" then
set theOrigin to {(theLeft + (maxWidth - newWidth) / 2), theBottom}
else
set theOrigin to {theLeft, theBottom}
end if
theLabel's setFrameOrigin:theOrigin
-- return theLabel, the top of the label, and its width
set my handlerResult to {theLabel, theBottom + theHeight, newWidth}
end createLabelMainThread: