OK, I’ve made progress, but I’m not sure how to integrate these with Dialog ToolkitPlus or Myriad Tables.
First, how do I set the initial date?
Second, how do I get the result form DTP or MT?
use framework "Foundation"
use AppleScript version "2.4"
use scripting additions
use script "Myriad Tables Lib"
set tableData to {{}}
set tableTitle to ""
set tablePrompt to ""
set multipleSelectionsAllowed to true
set canAddAndDelete to true
set editableColumns to {} -- Number List
set columnHeadings to {} -- Text List
set rowNumbering to true
set initiallySelectedRows to {} -- Number List
set emptySelectionAllowed to true
set rowTemplate to {}
set multipleLinesAllowed to true
set doubleclickMeansOK to true
set {datePicker, theTop, theWidth} to MakeDatePickerView(current date)
set newTable to make new table with data tableData ¬
with title tableTitle ¬
with prompt tablePrompt ¬
multiple selections allowed multipleSelectionsAllowed ¬
can add and delete canAddAndDelete ¬
editable columns editableColumns ¬
column headings columnHeadings ¬
row numbering rowNumbering ¬
initially selected rows initiallySelectedRows ¬
empty selection allowed emptySelectionAllowed ¬
multiple lines allowed multipleLinesAllowed ¬
double click means OK doubleclickMeansOK
--row template rowTemplate
set columnsToModify to {} -- Number List
set columnWidth to 20
set sortMethod to sort as Finder --sort case insensitive; sort case sensitive; sort localized case insensitive; sort localized case sensitive; sort none
set sortingDataColumn to 1 -- Number
set truncationStyle to truncate head --truncate middle; truncate tail
set headAlignment to align natural -- align center; align left; align right
set entryAlignment to align natural -- align center; align left; align right
set dateFormat to "mm/dd/yyyy"
set userDateFormat to ""
user format full -- user format long; user format medium; user format none; user format short
set realFormat to "" #,##0.00;-#,##0.00""
set integerFormat to "" #,###0;-#,##0""
set boldType to true
set monospacedDigits to true
set redNegatives to true
modify columns in table newTable ¬
columns list columnsToModify ¬
column width columnWidth ¬
sort method sortMethod ¬
sorting data column sortingDataColumn ¬
truncation style truncationStyle ¬
head alignment headAlignment ¬
entry alignment entryAlignment ¬
date format dateFormat ¬
user date format userDateFormat ¬
real format realFormat ¬
integer format integerFormat ¬
bold type boldType ¬
monospaced digits monospacedDigits ¬
red negatives redNegatives
set OKButtonName to ""
set OKButtonIsDefault to true
set cancelButtonName to ""
set extraButtonName to ""
set gridStyle to grid between columns -- grid between rows; grid between rows dashed; grid both; grid both dashed between rows; between rows and columns grid none
set columnWidthsPattern to {}
set highlightedRows to {}
set alternateBackgrounds to true
set rowDragging to true
set columnReordering to true
set hiddenCancelButton to true
set initialPosition to {10, 10, 300, 300}
modify table newTable ¬
OK button name OKButtonName ¬
OK button is default OKButtonIsDefault ¬
cancel button name cancelButtonName ¬
extra button name extraButtonName ¬
grid style gridStyle ¬
column widths pattern columnWidthsPattern ¬
highlighted rows highlightedRows ¬
alternate backgrounds alternateBackgrounds ¬
row dragging rowDragging ¬
column reordering columnReordering ¬
hidden cancel button hiddenCancelButton ¬
accessory view datePicker ¬
initial position initialPosition
set givingUpAfter to 60
set extendedResults to true
set tableResult to display table newTable ¬
giving up after givingUpAfter ¬
extended results extendedResults
on MakeDatePickerView(startingDate)
-- create date picker
set datePicker to current application's NSDatePicker's alloc()'s initWithFrame:(current application's NSMakeRect(0, 0, 280, 150))
datePicker's setDatePickerStyle:(current application's NSClockAndCalendarDatePickerStyle)
-- set initial date
datePicker's setDateValue:(current application's NSDate's |date|())
return {datePicker, 150, 280}
end MakeDatePickerView
With Dialog Toolkit Plus your best bet is to make your own custom version, incorporating your own code. It’s a bit tricky, but you should be able to work it out from the existing code.
I guess it can be used with Myriad Tables, but honestly, I think you’re just going to have to play trial-and-error.
I copied dialog toolkit plus and made two changes, (same line for alerts and windows).
I changed this
set end of controlResults to missing value
to this
set end of controlResults to aControl
I really hate to use a modified copy of DialogToolkitPlus, though, and I’m wondering if you would consider making that change in the next version, or making it an option?
It seems that it would work with most any accView, and anyone with the wherewithal to add a custom accView would be able to handle the raw control returned.
This script demonstrates how to add a date picker to a modified DialogToolKitPlus.
use framework "Foundation"
use AppleScript version "2.4"
use scripting additions
--use script "Myriad Tables Lib"
use script "BridgePlus" version "1.3.4"
use script "Dialog Toolkit Plus copy" version "1.1.3"
(*
Note: In the copy of Dialog Toolkit Plus, change the two occurances of this line:
set end of controlResults to missing value
to this
set end of controlResults to aControl
*)
set startingDate to (current date)
set time of startingDate to 0
set startingDate to startingDate + 1 * days
set accViewControls to {}
set controlResults to {}
set accViewWidth to 400
set theBottom to 0
set spacer to 12
set theTop to spacer
--Variables
set buttonList to ¬
{¬
("Cancel"), ¬
("Copy"), ¬
("Okay") ¬
}
set windowTitle to "Window title"
set initialPosition to {30, 30}
--Build window buttons
set {theButtons, theWidth} to create buttons buttonList ¬
default button 3 ¬
cancel button 1 ¬
equal widths false ¬
--button keys {textList}
if theWidth > accViewWidth then set accViewWidth to theWidth
-->ACC views go here
set {datePicker, theTop, theWidth} to MakeDatePickerView(startingDate)
set accViewControls to {datePicker}
--<<end ACC views
--Display Enhanced window
set accViewHeight to theTop
set {userResponse, valuesReturned} to ¬
display enhanced window windowTitle ¬
buttons theButtons ¬
acc view width accViewWidth ¬
acc view height accViewHeight ¬
acc view controls accViewControls ¬
initial position initialPosition ¬
with align cancel button
--giving up after 60
--active field 1
set dateReturned to dateValue of item 1 of valuesReturned
set dateReturned to ASify from dateReturned
--class of item 1 of valuesReturned
on MakeDatePickerView(startingDate)
-- create date picker
set startingDate to Cocoaify startingDate
set datePicker to current application's NSDatePicker's alloc()'s initWithFrame:(current application's NSMakeRect(0, 0, 280, 150))
datePicker's setDatePickerStyle:(current application's NSClockAndCalendarDatePickerStyle)
-- set initial date
datePicker's setDateValue:startingDate
return {datePicker, 150, 280}
end MakeDatePickerView
The ASObjC code is just a wrapper around Objective-C code, and it’s the latter you’d have to modify.
The picker is a control, so you can try setting your script to its target and add a handler as its action. Then your handler should get called when the user interacts with the picker. Something like:
thePicker's setTarget:me
thePicker's setAction:"pickerStuff:"
on pickerStuff:thePicker
-- get values you want here
end pickerStuff:
The result should be an NS Date object that can be ASified into an AppleScript date; or even a text value.
But nothing seems to come back to the handler or the script.
on MakeDatePickerView(startingDate)
-- create date picker
set myPath to path to me
set startingDate to Cocoaify startingDate
set datePicker to current application's NSDatePicker's alloc()'s initWithFrame:(current application's NSMakeRect(0, 0, 280, 150))
datePicker's setDatePickerStyle:(current application's NSClockAndCalendarDatePickerStyle)
-- set initial date
datePicker's setDateValue:startingDate
datePicker's setAction:"pickerStuff"
datePicker's setTarget:me
return {datePicker, 150, 280}
end MakeDatePickerView
on pickerStuff:datePicker
dateInfo
end pickerStuff:
There’s no return value – the action handler is called asynchronously. You set it up, the handler gets called when the table is showing, and you use the value when the table is finished with.
You’ll have to query the picker in the action handler. Something like this:
on pickerStuff:datePicker
set my theDate to datePicker's dateValue() -- where theDate is a global so you can get the value later
end pickerStuff:
This is ringing a bell. Wasn’t there something like this in your MT samples, where your script displayed a dialog without closing the MT window? Is it like that?
OK, this approach of adding a date picker to MT isn’t really working for me. (smallest error leaves SD in an unstable state requiring a force quit; the change to the date is updated in the script as it’s made rather than when the OK button is hit).
I’m going with a different strategy. Rather than use the date picker with Myriad Tables, I’ll have the user select the item in MT, then bring up a new window(s) to pick the date(s).
It may be a better solution than what I was planning.
These tools, Myriad Tables and Dialog Toolkit Plus, are so powerful, I’ve got to be careful I don’t fill the user with too much information and choices in one window.
FYI, for those also trying incorporate other accessory views into Dialog Toolkit Plus, I’m trying with a strategy that doesn’t replace DT+ with a different library, but only adds a library with two commands from DT+:
Display Enhanced Window
Display Enhanced Alert
These commands will be renamed as:
Display Extended Window
Display Extended Alert
And adds commands with additional AccViews. For now they will be:
Create Date Picker
Create Combo Box
The idea is that DT+ commands will be used to create all the UI views it now does, along with everything else, but the new version: “Dialog Toolkit Extended” will be used to create the additional views and display them.
For those two views I’ll convert the result to an appleScript date, and a string value. For any other views it will return the raw value.
I’m going to borrow (steal) the library script provided by @georgeorwell here to do all the heavy lifting
@estockly@ShaneStanley it might be cool to create a topic here or on Macscripter that houses mods for Shane’s libraries. I have played with his Dialog Toolkit and added Color Popups to choose from colors, an indefinite time-out and probably few other items. The key is documenting well so when it needs upgrades, it’s easier.