A Noob Question From An Experienced Scripter: What's The Definition Of "Accessory View"?

Hello,

I’m fluent in AppleScript but not so in AppleScript-ObjC and its applications. Since I used the now discontinued 24UAppearance OSAX scripting addition that allowed enhanced user interaction on old macOS – unfortunately, the development of this addition was dropped with the roll-out of Mojave – I downloaded and installed Dialog Toolkit+ to regain the lost functionality and set about looking into its feature set. I perused the script sample published in this forum section but as detailed as it was I’d like to get to the bottom regarding the term of “accessory view” as in

acc view width integer : The width of the accessory view in points

I’m not a developer so the terminology appears a tad muddy. Is “accessory view” another word for a UI element? I appreciate someone shedding light.

It can be a UI element, or a view containing one or more UI elements.

2 Likes

As Shane pointed out it’s an additional view you can add to the standard “Alerts” which provide Header Text, Info text and Buttoms. I use accessory views when wanting to allow
The user to provide more information.
After the alert is completed (ends modal) I can check the elements I provided to the accessory view and get data from them such as a textfield’s string value, a check buttons state etc

The only places I use accessory views are Shane’s DialogToolkitPlus and Shane’s Myriad tables.

They give my scripts a far better user interface.

If you want to explore their use I’d look at the documentation and examples provided with DialogToolkit.

Freeware | Late Night Software

Dialog Toolkit Plus v1.1.2

Dialog Toolkit Plus is an ASObjC-based script library for showing enhanced dialogs. Add multiple text entry fields, checkboxes, popup menus, radio buttons, path controls, extra buttons, secure fields, images, and rules to dialogs. It requires macOS 10.10 or later.

Thanks, I know where to download them, and I know what this piece of software does. All I wanted was to clarify the term accessory view, hence the reason I created this thread. The words accessory and view seemed confusing. The former implies an auxiliary function (a synonym of appendage, addition, attachment) and the latter sounds too general.
From the documentation, it gives the impression that accessory view is every UI element of the dialog except the title bar, the icon and the buttons. In this interpretation, the bottom of accessory view and the top of accessory view refer to the area made by exclusion of the aforementioned elements not relative to the edge of the dialog’s body. Is it the case?

And that’s the case.

An example might help. Consider a save dialog. There are several fixed elements – the sidebar, the stuff at the top, the list, and the buttons. And app can modify these is minor ways, but that’s all. But it can provide an accessory view, and the OS will place it above the buttons at the bottom.

This is how apps customize various otherwise-fixed dialogs.

1 Like

Is there a source for other accessory views we could use for Dialog Toolkit Plus and Myriad tables, beyond those included with Dialog Toolkit Plus?

Specifically, I’m looking for:
• Date picker
• Time picker
• Date and Time picker

I can do a clunky version of each with Dialog Toolkit plus, but I’d prefer one of the fancy apple UI pickers.

Any suggestions?

1 Like

Any subclass of NSView is fine, including NSDatePicker.

1 Like

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

1 Like

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.

OK, The script below is working now, thanks!

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


Lots of people have made good improvements, and I’m loathe to pick and choose. It’s a toolkit in the sense of being something for users to build upon.

Hey Ed,

That’s pretty spiffy…   :sunglasses:

Do you have one with a type-able time instead of or in addition to the clock face?

-Chris

I get that, but I’ve got a feeling that any modifications involving accessory views start with those two lines.

Rather than modifying Dialog Toolkit Plus, I’m thinking of making an auxillary Library that calls DTP for everything but those two commands.

That’s in progress, Chris, but have a look at the Dialog Toolkit version in this post:

1 Like

Spiffy!

I’ll consume that critter when I have some time.

Thanks.

Any way you could release an editable version of Myriad Tables?

It can display the date picker, but there’s no way to get the result.

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:
1 Like

Doesn’t seem to be working…

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: