[ANN] Table dialogs

Hello Shane,

I am a newby. Can you advise me where to located the Lib in my system?
I put the folder in my /Library/scripts folder, but the sample scripts aren’t able to access the Lib.
Thanks for any help.

Open your ~/Library folder. If you have never used script libraries before, you will need to crate a new folder called Script Libraries in it. Put the file Myriad Tables Lib.scptd inside the Script Libraries folder.

Thanks Shane, that worked.

Shane, this is totally awesome!

Thank you so very, very much for sharing this script library. I don’t know why you don’t sell stuff like this. I would easily pay $10 (or more). At least you should have a “contributions” web page.

I have been looking for over a year for a way to have more complex dialogs in AppleScript, particularly one with a drag/drop feature. There are so many things that you have enabled with your script library.

And not only did you give us a great script lib, you provided an outstanding scripting dictionary, and examples. Wow!!!

You have my undying gratitude.

Best Regards,
JMichaelTX

I’m glad you like it. I’ve been wanting something similar for a long time myself, so I’m pleased with how it worked out. Tables are complex, but they can also serve a range of purposes.

I’m open to donations, but I’d prefer people buy a copy of my book or app – that way they get something extra they hopefully find useful.

Thanks again Shane.

To add a little, and get some feedback, here is a simple example I have modified to show how to process the results of the table dialog. Very easy, really. I found it easy to understand and modify Shane’s code.

I’m sure my code is far from optimized, so if anyone has suggestions for improvement, don’t hesitate to post.


use AppleScript version "2.4"
use scripting additions
use script "Myriad Tables Lib"

set theHeads to {"First Name", "Last Name", "Index", "Police", "Score", "Some Date"}
set theDate to current date
set someData to {{"Saga", "Norén", 1, true, 12.0, theDate}, ¬
	{"Rasmus", "Larsson", 2, true, 13.5, missing value}, ¬
	{"Freddie", "Holst", 3, false, 9.0, theDate + 40000}, ¬
	{"Claes", "Sandberg", 4, false, 1.23456789E+4, theDate + 50000}, ¬
	{"John", "Lundqvist", 5, true, 13.4567, theDate + 30000}, ¬
	{"Annika", "Melander", 6, false, 22.0, theDate + 60000}}

-- typical process: make it with "table dialog with data", modify if required, then display

set myTable to ¬
	make new table with data someData ¬
		with title "Sample table" column headings theHeads ¬
		with prompt ¬
		"You can drag/drop, select multiple rows. Everything is editable. Uses a row template" editable columns {} ¬
		row template {"", "", 1, true, 1.0, current date, missing value} ¬
		with multiple selections allowed, row numbering and empty selection allowed

modify table myTable ¬
	highlighted rows {2, 4} grid style grid both dashed between rows ¬
	OK button name "Cool"

modify table myTable with row dragging -- CHG:  dragging

set theResult to display table myTable with extended results -- CHG: ext res

--- PROCESS THE RESULTS IN THE ORDER SET BY USER ---

set rowOrder to order of rows of theResult
log rowOrder

set numRows to count of someData
log numRows
set AppleScript's text item delimiters to {" | "}

repeat with iRow from 1 to numRows
	
	set rowNum to item iRow of rowOrder
	log ("[" & rowNum & "]:  " & (item rowNum of someData))
	
end repeat

The log looks like this:


(*6, 1, 4, 3, 2, 5*)
(*6*)
(*[6]:  Annika | Melander | 6 | false | 22.0 | Sun, Feb 14, 2016 at 3:29 PM*)
(*[1]:  Saga | Norén | 1 | true | 12.0 | Sat, Feb 13, 2016 at 10:49 PM*)
(*[4]:  Claes | Sandberg | 4 | false | 1.23456789E+4 | Sun, Feb 14, 2016 at 12:42 PM*)
(*[3]:  Freddie | Holst | 3 | false | 9.0 | Sun, Feb 14, 2016 at 9:56 AM*)
(*[2]:  Rasmus | Larsson | 2 | true | 13.5 | missing value*)
(*[5]:  John | Lundqvist | 5 | true | 13.4567 | Sun, Feb 14, 2016 at 7:09 AM*)

Which properties of the result you use depends a lot on what you’re using the table for. For instance, if everything is editable, as it is in your example, you probably want the values returned property. If you’re using it to have a user just reorder things, order of rows will be what matters to you. If you’re putting up information for the user to check and correct, you might find altered rows is quicker than comparing before and after. Because tables perform different roles, the results need to be flexible.

Excellent point. I wasn’t trying to suggest that my code was the only way to process the results. It is clearly just one way – a very simple example.

Maybe others will post how they have used the results in other ways.

One question while I’m here: I know you are not a big fan of JXA, but I have some JXA scripts that I would like to use Myriad Tables with. Is there any reason your script lib won’t work with JXA?

Have you tried it?

FWIW, the script is just a small amount of ASObjC code acting as a wrapper around an Objective-C framework – the framework does all the actual work.

Yep. Getting this error:

Any ideas/suggestions?

One Note: Where you had “missing data” in AppleScript, I used “null” in JavaScript.
Is this correct?

I also tried an empty string “”, but got same results.

Actually JavaScript


'use strict';

var app = Application.currentApplication()
app.includeStandardAdditions = true

var myLib = Library('JMichael.Lib.JXA')

var MTLib = Library('Myriad Tables Lib')

myLib.helloJS("Called by JXA script")		// works fine


var theHeads = ["First Name", "Last Name", "Index", "Police", "Score", "Some Date"]
var theDate = new Date()
var someData = [
    ["Saga", "Norén", 1, true, 12.0, theDate],
    ["Rasmus", "Larsson", 2, true, 13.5, null],
    ["Freddie", "Holst", 3, false, 9.0, (theDate + 40000)],
    ["Claes", "Sandberg", 4, false, 1.23456789E+4, theDate + 50000],
    ["John", "Lundqvist", 5, true, 13.4567, theDate + 30000],
    ["Annika", "Melander", 6, false, 22.0, theDate + 60000]
	];
	
console.log(someData)

/*
--- AppleScript Code ---
set myTable to ¬
	make new table with data someData ¬
		with title "Sample table" column headings theHeads ¬
		with prompt ¬
		"You can drag/drop, select multiple rows. Everything is editable. Uses a row template" editable columns {} ¬
		row template {"", "", 1, true, 1.0, current date, missing value} ¬
		with multiple selections allowed, row numbering and empty selection allowed
*/


var myEditCol = []
var myRowTemplate = ["", "", 1, true, 1.0, theDate, null]

//*** NEXT LINE GIVES ERROR ***
//	Script Error
//	Error on line 45: Error: Script error.

var myTable = MTLib.makeNewTableWithData(someData,
		{withTitle: "Sample table",
		columnHeadings: theHeads,
		withPrompt: "You can drag/drop, select multiple rows. Everything is editable. Uses a row template",
		editableColumns: myEditCol,
		rowTemplate: myRowTemplate,
		multipleSelectionsAllowed: true, 
		rowNumbering: true,
		emptySelectionAllowed: true
		}
		);

REPLIES PANEL:


app = Application("Script Editor")
	app.displayAlert("From My JXA Lib:  Called by JXA script")
		--> {"buttonReturned":"OK"}
/* Saga,Norén,1,true,12,Sun Feb 14 2016 20:31:23 GMT-0600 (CST),Rasmus,Larsson,2,true,13.5,,Freddie,Holst,3,false,9,Sun Feb 14 2016 20:31:23 GMT-0600 (CST)40000,Claes,Sandberg,4,false,12345.6789,Sun Feb 14 2016 20:31:23 GMT-0600 (CST)50000,John,Lundqvist,5,true,13.4567,Sun Feb 14 2016 20:31:23 GMT-0600 (CST)30000,Annika,Melander,6,false,22,Sun Feb 14 2016 20:31:23 GMT-0600 (CST)60000 */
app = Application("Script Editor")
	app.alloc([])
		--> Error -1708: Message not understood.
Result:
Error -1753: Script error.

I suspect you’re out of luck. The “table” returned is an AppleScript script object wrapping a pointer, and it looks like js can’t deal with that.

Thanks for the info. Not what I wanted to hear, but at least I can quit butting my head against a brick wall. :frowning:

How to we report this issue to Apple? Surely they intend for AppleScript and JXA to support the same objects.

Not in this sort of case. There are probably workarounds, but to be honest, I don’t think they’re worth my while.

FYI, version 1.0.1 is now available. Fixes an issue where boolean values would sometimes be returned as 0 or 1 rather than true or false.

FYI, version 1.0.6 is now available. Changes are:

  • Ability to show cells containing more than one line;

  • Ability to hide the Cancel button;

  • Improved handling of threading issues with accessory views;

  • Ability to specify monospaced digits (10.11 and later only);

  • Ability to have negative numbers appear in red;

  • Ability to have column(s) appear in bold;

  • Japanese localization.

You can download it here:

www.macosxautomation.com/applescript/apps/Script_Libs.html

Version 1.0.7 of Myriad Tables Lib is now available from:

www.macosxautomation.com/applescript/apps/Script_Libs.html

  • Introduces the ‘double click means OK parameter’ to the ‘make new table with data’ and ‘display table with data’ commands.

  • The ‘modify table’ command has a new ‘initial position’ parameter.

  • The ‘table reply’ and ‘extended table reply’ records include a new ‘final position’ value.

FYI, I’ve just released version 1.0.8. It fixes a problem that occurs in scripts run from the Scripts menu in some versions of Script Debugger.

Version 1.0.9 of Myriad Tables Lib is now available here:

https://www.macosxautomation.com/applescript/apps/Script_Libs.html

This version fixes issues in Dark Mode when running in macOS 10.14. It also adds the ability to have a text column displayed securely with letters appearing as bullet characters, and German localization has been added.

Dear all
a quick question:
I might have miss this, but I couldn’t find a “built-in” method for sorting the table (based on a specific column) prior display to the user …

I this possible?
It seems to me the the “sorting data column” should do this, but I couldn’t make to work.

Thanks

You didn’t miss it: preparing the initial data is left to the user.