Wednesday, November 20, 2019

#1 2016-02-12 08:21:43 pm

Shane Stanley
Member
From:: Australia
Registered: 2002-12-07
Posts: 6035

[ANN] Table dialogs

Myriad Tables Lib is a script library that enables scripts to display dialogs containing tables. The tables can be simple ones similar to that shown by the choose from list command, to tables of up to 99 columns and hundreds of rows featuring formatted numbers and dates, as well as checkboxes, popup menus and combo boxes.

The dialogs are resizable and the tables can be configured in a variety of ways. They can support sorting, dragging of rows, drag-and-drop from the Finder, addition and deletion of rows, and a range of formatting options.

Using it is pretty simple. For example, to create a table with checkboxes in the first row, you could use this:

Applescript:

use script "Myriad Tables Lib"

display table with data {{true, "One"}, {false, "Two"}, {true, "Three"}, {false, "Four"}, {true, "Five"}} editable columns {1} with prompt "These checkboxes can be clicked" with empty selection allowed

Myriad Tables Lib is free, and requires OS X 10.10 or later. You can download the library, docs, and some samples here:

www.macosxautomation.com/applescript/ap … dTablesLib

Enjoy.


Shane Stanley <sstanley@myriad-com.com.au>
www.macosxautomation.com/applescript/apps/
latenightsw.com

Offline

 

#2 2016-02-13 10:38:54 am

hve
Member
Registered: 2006-02-02
Posts: 11

Re: [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.

Offline

 

#3 2016-02-13 02:28:32 pm

Shane Stanley
Member
From:: Australia
Registered: 2002-12-07
Posts: 6035

Re: [ANN] Table dialogs

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.


Shane Stanley <sstanley@myriad-com.com.au>
www.macosxautomation.com/applescript/apps/
latenightsw.com

Offline

 

#4 2016-02-13 03:02:10 pm

hve
Member
Registered: 2006-02-02
Posts: 11

Re: [ANN] Table dialogs

Thanks Shane, that worked.

Offline

 

#5 2016-02-13 06:09:59 pm

JMichaelTX
Member
From:: Houston, TX (The Woodlands)
Registered: 2014-07-12
Posts: 139

Re: [ANN] Table dialogs

Shane Stanley wrote:

Myriad Tables Lib is a script library that enables scripts to display dialogs containing tables. The tables can be simple ones similar to that shown by the choose from list command, to tables of up to 99 columns and hundreds of rows featuring formatted numbers and dates, as well as checkboxes, popup menus and combo boxes.

www.macosxautomation.com/applescript/ap … dTablesLib

Enjoy.


Shane, this is totally awesome!
Awesome-Thumbs-up.gif

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


iMac-27 Late 2015 Retina 5K Screen (& others)
macOS 10.11.6 (El Capitan)

Offline

 

#6 2016-02-13 06:54:10 pm

Shane Stanley
Member
From:: Australia
Registered: 2002-12-07
Posts: 6035

Re: [ANN] Table dialogs

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.


Shane Stanley <sstanley@myriad-com.com.au>
www.macosxautomation.com/applescript/apps/
latenightsw.com

Offline

 

#7 2016-02-13 11:01:33 pm

JMichaelTX
Member
From:: Houston, TX (The Woodlands)
Registered: 2014-07-12
Posts: 139

Re: [ANN] Table dialogs

Shane Stanley wrote:

Myriad Tables Lib is a script library that enables scripts to display dialogs containing tables. The tables can be simple ones similar to that shown by the choose from list command, to tables of up to 99 columns and hundreds of rows featuring formatted numbers and dates, as well as checkboxes, popup menus and combo boxes.


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.

Applescript:


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:

Applescript:


(*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*)


iMac-27 Late 2015 Retina 5K Screen (& others)
macOS 10.11.6 (El Capitan)

Offline

 

#8 2016-02-14 12:20:59 am

Shane Stanley
Member
From:: Australia
Registered: 2002-12-07
Posts: 6035

Re: [ANN] Table dialogs

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.


Shane Stanley <sstanley@myriad-com.com.au>
www.macosxautomation.com/applescript/apps/
latenightsw.com

Offline

 

#9 2016-02-14 06:23:30 pm

JMichaelTX
Member
From:: Houston, TX (The Woodlands)
Registered: 2014-07-12
Posts: 139

Re: [ANN] Table dialogs

Shane Stanley wrote:

Which properties of the result you use depends a lot on what you're using the table for.
. . .


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?


iMac-27 Late 2015 Retina 5K Screen (& others)
macOS 10.11.6 (El Capitan)

Offline

 

#10 2016-02-14 06:27:43 pm

Shane Stanley
Member
From:: Australia
Registered: 2002-12-07
Posts: 6035

Re: [ANN] Table dialogs

JMichaelTX wrote:

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.


Shane Stanley <sstanley@myriad-com.com.au>
www.macosxautomation.com/applescript/apps/
latenightsw.com

Offline

 

#11 2016-02-14 08:42:28 pm

JMichaelTX
Member
From:: Houston, TX (The Woodlands)
Registered: 2014-07-12
Posts: 139

Re: [ANN] Table dialogs

Shane Stanley wrote:
JMichaelTX wrote:

Is there any reason your script lib won't work with JXA?


Have you tried it?.


Yep.  Getting this error:

Script Error
    Error on line 45: Error: Script error.

And in the Result panel:

Result:
Error -1753: Script 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

Applescript:


'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:

Applescript:


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.


iMac-27 Late 2015 Retina 5K Screen (& others)
macOS 10.11.6 (El Capitan)

Offline

 

#12 2016-02-14 09:41:21 pm

Shane Stanley
Member
From:: Australia
Registered: 2002-12-07
Posts: 6035

Re: [ANN] Table dialogs

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.


Shane Stanley <sstanley@myriad-com.com.au>
www.macosxautomation.com/applescript/apps/
latenightsw.com

Offline

 

#13 2016-02-14 10:41:21 pm

JMichaelTX
Member
From:: Houston, TX (The Woodlands)
Registered: 2014-07-12
Posts: 139

Re: [ANN] Table dialogs

Shane Stanley wrote:

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.  sad

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


iMac-27 Late 2015 Retina 5K Screen (& others)
macOS 10.11.6 (El Capitan)

Offline

 

#14 2016-02-15 12:37:27 am

Shane Stanley
Member
From:: Australia
Registered: 2002-12-07
Posts: 6035

Re: [ANN] Table dialogs

JMichaelTX wrote:

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.


Shane Stanley <sstanley@myriad-com.com.au>
www.macosxautomation.com/applescript/apps/
latenightsw.com

Offline

 

#15 2016-02-15 05:23:55 pm

Shane Stanley
Member
From:: Australia
Registered: 2002-12-07
Posts: 6035

Re: [ANN] Table dialogs

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.


Shane Stanley <sstanley@myriad-com.com.au>
www.macosxautomation.com/applescript/apps/
latenightsw.com

Offline

 

#16 2016-12-02 10:52:10 pm

Shane Stanley
Member
From:: Australia
Registered: 2002-12-07
Posts: 6035

Re: [ANN] Table dialogs

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/ap … _Libs.html


Shane Stanley <sstanley@myriad-com.com.au>
www.macosxautomation.com/applescript/apps/
latenightsw.com

Offline

 

#17 2017-02-22 05:45:21 pm

Shane Stanley
Member
From:: Australia
Registered: 2002-12-07
Posts: 6035

Re: [ANN] Table dialogs

Version 1.0.7 of Myriad Tables Lib is now available from:

www.macosxautomation.com/applescript/ap … _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.


Shane Stanley <sstanley@myriad-com.com.au>
www.macosxautomation.com/applescript/apps/
latenightsw.com

Offline

 

#18 2017-04-22 09:37:41 pm

Shane Stanley
Member
From:: Australia
Registered: 2002-12-07
Posts: 6035

Re: [ANN] Table dialogs

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.


Shane Stanley <sstanley@myriad-com.com.au>
www.macosxautomation.com/applescript/apps/
latenightsw.com

Offline

 

#19 2019-03-07 08:32:36 pm

Shane Stanley
Member
From:: Australia
Registered: 2002-12-07
Posts: 6035

Re: [ANN] Table dialogs

Version 1.0.9 of Myriad Tables Lib is now available here:

https://www.macosxautomation.com/apples … _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.


Shane Stanley <sstanley@myriad-com.com.au>
www.macosxautomation.com/applescript/apps/
latenightsw.com

Offline

 

Board footer

Powered by FluxBB

RSS (new topics) RSS (active topics)