Friday, April 28, 2017

#1 2017-02-25 02:24:48 pm

t.spoon
Member
From: BFE, Massachusetts
Registered: 2013-01-12
Posts: 130

Change elements dynamically using Shane's Dialog Toolkit?

I've been messing around with it and am thinking the answer is probably "no," but I'm wondering if there's a way to have the selection in one UI element control the contents of another using Shane's Dialog Toolkit? (or any other way)

https://www.macosxautomation.com/apples … logToolkit

Here's a screenshot of what I'm trying to replicate:
https://www.dropbox.com/s/tupsftxoqfkl2 … g.png?dl=0

In that dialog, the second UI element, "Step 2," is blank when the dialog comes up, and the options are populated based on what was selected from the dropdown in Step 1.

I haven't been able to figure out a way to do anything like this in Applescript, but thought it wouldn't hurt to ask.

It also looks like an equivalent to AS's "Choose from list" isn't available in Dialog Toolkit, which is how "Step 2" in that screeshot functions. However, while it's unfortunate the required mouse targeting is more precise, it looks like I could just use "create labeled matrix" with the "with arranged vertically" argument to get pretty close. But I would have to have different sets of options for that and populate them based on the selection in the "Step 1" drop-down.

(BTW, I just found Dialog Toolkit and can't believe I didn't know about it earlier, I've done a lot of searches looking for anything like a modern replacement for Facespan, looking at X-Code & Smile, etc, and I even have Shane's book and still had somehow failed to come across this library until now. It's incredibly useful. So thanks again, Shane, if you're reading this.)

Offline

 

#2 2017-02-25 07:50:03 pm

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

Re: Change elements dynamically using Shane's Dialog Toolkit?

t.spoon wrote:

I'm wondering if there's a way to have the selection in one UI element control the contents of another using Shane's Dialog Toolkit? (or any other way)

Once you head down that road, moving to Xcode starts to make more sense. Nonetheless, you can do what you want in Dialog Toolkit. Let's say you keep the first popup, and make the second list another popup whose content changes when a selection is made from the first.

Each control is a subclass of NSResponder, which means they respond to user interaction. And the way they respond is defined by two things: the action, which is what you want to happen, and the target, which is the object that contains the code you want to be run.

So for your first popup you need to set the target:

Applescript:

thePopup's setTarget:me

And then the action. The action is the name of the method/handler to be called, and must take a single argument -- a reference to the control is passed as this argument. So something like:

Applescript:

thePopup's setAction:"rebuildList:"

Then you need to add the handler. You will also need to make sure the variable representing the second control is a property, so you can access it within the handler. You handler might be like this:

Applescript:

on rebuildList:sender -- sender is the popup
set theTitle to sender's titleOfSelectedItem() as text
my secondPopup's removeAllItems() -- secondPopup is a property
if theTitle = "Whatever" then
my secondPopup's addItemsWithTitles:{"One", "Two", "Three"}
else
my secondPopup's addItemsWithTitles:{"Four", "Five", "Six"}
...

If you look at Chapter 27 in my book, you can see something similar in the accessory view checkbox sample.


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

Offline

 

#3 2017-02-25 08:26:19 pm

t.spoon
Member
From: BFE, Massachusetts
Registered: 2013-01-12
Posts: 130

Re: Change elements dynamically using Shane's Dialog Toolkit?

Fantastic! I won't have a chance to mess with it again until Monday, but this looks very promising.

As always, thanks.

- Tom.

Offline

 

#4 2017-03-13 04:06:06 pm

t.spoon
Member
From: BFE, Massachusetts
Registered: 2013-01-12
Posts: 130

Re: Change elements dynamically using Shane's Dialog Toolkit?

I finally found time to dig into this again.

Changing the selection on the first popup is not changing the options on the matrix after it, which is what I'm going for.

When I click "OK," I get the error:

"Stopped: (Error: missing value doesn't understand the "title" message)
the AppleEvent was not handled by any handler (errAEEventNotHandled:-1708)"

Probably a simple stupid mistake on my end, but I'm a total noob with AS Obj C.

Any pointers on where I've gone wrong?

I'll have some other dialogs with variable data in the future, so can you point me toward the place to discover the syntax for things like "removeAllItems" and "addItemsWithTitles" ? Those are not things I would have known how to find.

Thanks,

Tom.

Applescript:

use AppleScript version "2.4" -- Yosemite (10.10) or later
use framework "Foundation"
use scripting additions

use script "Dialog Toolkit" version "2.0"

property printAreaMatrix : {}

set theTop to -10

set theSavePath to "Fill This in Later"

set orderList to {"234567 - Bob Roberts - QTY: 6", "345678 - Bob Plant - QTY: 10,000", "456789 - Marshmellow Fiddlesticks - QTY: 1"}

set listOfTabLists to {{"Tab 1 - Front - Screen Print - Qty:1", "Tab 1 - Back - DTG - Qty:1"}, {"Tab 1 - Front - Screen Print - Qty:50", "Tab 1 - Back - DTG - Qty:50", "Tab 2 - Front - Screen Print - Qty:100", "Tab 2 - Back - Digital Vinyl - Qty:100", "Tab 3 - Front - Screen Print - Qty:1,000", "Tab 3 - Back - Screen Print - Qty:1,000"}}

set theProductionMethods to {"SP - Screen Printing", "DTG - Direct To Garment", "EMB - Embroidery", "DV - Digital Vinyl", "VIN - Regular Vinyl"}

set theLabelStrings to {"ORDER:", "PRINT AREA:", "OPTIONAL - Override Production Method:", "OPTIONAL - Edit Print Area Name:", "Your File Save Path Will Be:"}



set {thePath, theTop} to create label theSavePath left inset 0 bottom (theTop + 10) max width 400 aligns left without multiline

set {thePathLabel, theTop} to create label (item 5 of theLabelStrings) left inset 0 bottom (theTop + 10) max width 400 aligns left without multiline

set {fileNameField, fileNameLabel, theTop, fieldLeft} to create side labeled field "" placeholder text "Rt Sleeve" left inset 0 bottom (theTop + 10) total width 400 label text (item 4 of theLabelStrings) field left 0

set {printMethodPopup, printMethodLabel, theTop} to create labeled popup theProductionMethods left inset 0 bottom theTop + 10 popup width 200 max width 400 label text (item 3 of theLabelStrings) popup left 0

set {printAreaMatrix, printAreaMatrixLabel, theTop, matrixLeft} to create labeled matrix item 2 of listOfTabLists left inset 0 bottom theTop + 10 max width 400 matrix left 0 label text (item 2 of theLabelStrings) with arranged vertically

set {orderPopup, orderLabel, theTop} to create labeled popup orderList left inset 0 bottom theTop + 10 popup width 400 max width 400 label text (item 1 of theLabelStrings) popup left 0

orderPopup's setTarget:me
orderPopup's setAction:"setOrderList:"


set allControls to {orderPopup, orderLabel, printAreaMatrix, printAreaMatrixLabel, printMethodPopup, printMethodLabel, fileNameField, fileNameLabel, thePathLabel, thePath}

set {buttonName, suppressedState, controlsResults} to display enhanced alert "Send for output" message "" as informational alert buttons {"Cancel", "OK"} giving up after 120 acc view width 500 acc view height theTop acc view controls allControls without suppression

on setOrderList(sender, listOfTabLists)
   set currentSelection to sender's titleOfSelectedItem() as text
   my printAreaMatrix's removeAllItems()
   if currentSelection is "234567 - Bob Roberts - QTY: 6" then
       my (printAreaMatrix's addItemsWithTitles:(item 1 of listOfTabLists))
   else
       my (printAreaMatrix's addItemsWithTitles:(item 2 of listOfTabLists))
   end if
end setOrderList

Offline

 

#5 2017-03-13 06:14:55 pm

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

Re: Change elements dynamically using Shane's Dialog Toolkit?

You have a couple of problems.

First, action handlers have a fixed format: they can only take a single argument, which is the sender:

Applescript:

on setOrderList:sender

Second, matrixes don't support removeAllItems or addItemsWithTitles: -- they're for popups.  You will probably have to rename existing entries and add/remove extras. Changing the number of entries in a matrix is generally a bad move, because it's also likely to change the size of the whole dialog, which can appear disconcerting. I think you'd be better to have another popup instead.

It's also worth having Console running while you debug stuff with action handler. Then you see entries like this:

*** -[BAGenericObjectNoDeleteOSAID setOrderList:]: -[NSMatrix removeAllItems]: unrecognized selector sent to instance 0x7f88c0b93630 (error -10000)

I'll have some other dialogs with variable data in the future, so can you point me toward the place to discover the syntax for things like "removeAllItems" and "addItemsWithTitles" ? Those are not things I would have known how to find.

You need to search on the name of the class of the control -- they'll be listed among the control's methods (or its superclass's methods). If you use Script Debugger, its code-completion can also help by providing the correct options is some cases.


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

Offline

 

#6 2017-03-15 06:06:19 pm

t.spoon
Member
From: BFE, Massachusetts
Registered: 2013-01-12
Posts: 130

Re: Change elements dynamically using Shane's Dialog Toolkit?

Thanks so much Shane, I've got that working great now.

The other thing I need to update to get through this dialog is the last label in my dialog window, named "thePath."

I've been searching, I'm not finding commands for changing that beyond "setStringValue:"

I did Google up other people with issues changing that - saying it doesn't update just by changing the value, but their solutions immediately get waay over my head.

http://www.cocoabuilder.com/archive/coc … perly.html

It's my "on setThePath:sender" handler that's not doing anything.

Any help? Any other ASObjC users following along who wants to give Shane a break and give me a hint?

I apologize for having not found time to read Shane's book yet, perhaps I could spare you all from my questions.

Thanks,

Tom.

Applescript:

use AppleScript version "2.4" -- Yosemite (10.10) or later
use framework "Foundation"
use scripting additions

use script "Dialog Toolkit" version "2.0"

property listOfTabLists : {}
property orderList : {}

set theTop to -10

set theSavePath to "Fill This in Later"

set orderList to {"234567 - Bob Roberts - QTY: 6", "345678 - Bob Plant - QTY: 10,000", "456789 - Marshmellow Fiddlesticks - QTY: 1"}

set listOfTabLists to {{"Tab 1 - Front - Screen Print - Qty:1", "Tab 1 - Back - DTG - Qty:1"}, {"Tab 1 - Front - Screen Print - Qty:50", "Tab 1 - Back - DTG - Qty:50", "Tab 2 - Front - Screen Print - Qty:100", "Tab 2 - Back - Digital Vinyl - Qty:100", "Tab 3 - Front - Screen Print - Qty:1,000", "Tab 3 - Back - Screen Print - Qty:1,000"}, {"Tab 1 - Front - Blank - Qty:1"}}

set theProductionMethods to {"SP - Screen Printing", "DTG - Direct To Garment", "EMB - Embroidery", "DV - Digital Vinyl", "VIN - Regular Vinyl"}

set theLabelStrings to {"ORDER:", "PRINT AREA:", "OPTIONAL - Override Production Method:", "OPTIONAL - Edit Print Area Name:", "Your File Save Path Will Be:"}



set {thePath, theTop} to create label theSavePath left inset 0 bottom (theTop + 10) max width 400 aligns left without multiline

set {thePathLabel, theTop} to create label (item 5 of theLabelStrings) left inset 0 bottom (theTop + 10) max width 400 aligns left without multiline

set {fileNameField, fileNameLabel, theTop, fieldLeft} to create side labeled field "" placeholder text "Rt Sleeve" left inset 0 bottom (theTop + 10) total width 400 label text (item 4 of theLabelStrings) field left 0

set {printMethodPopup, printMethodLabel, theTop} to create labeled popup theProductionMethods left inset 0 bottom theTop + 10 popup width 200 max width 400 label text (item 3 of theLabelStrings) popup left 0

set {printAreaPopop, printAreaPopupLabel, theTop, matrixLeft} to create labeled popup (item 1 of listOfTabLists) left inset 0 bottom theTop + 10 popup width 300 max width 400 label text (item 2 of theLabelStrings) popup left 0

set {orderPopup, orderLabel, theTop} to create labeled popup orderList left inset 0 bottom theTop + 10 popup width 400 max width 400 label text (item 1 of theLabelStrings) popup left 0

orderPopup's setTarget:me
orderPopup's setAction:"setOrderList:"
printAreaPopop's setTarget:me
printAreaPopop's setAction:"setThePath:"


set allControls to {orderPopup, orderLabel, printAreaPopop, printAreaPopupLabel, printMethodPopup, printMethodLabel, fileNameField, fileNameLabel, thePathLabel, thePath}

set {buttonName, suppressedState, controlsResults} to display enhanced alert "Send for output" message "" as informational alert buttons {"Cancel", "OK"} giving up after 120 acc view width 500 acc view height theTop acc view controls allControls without suppression

on setThePath:sender
   my thePath's setStringValue("Updated String")
end setThePath:

on setOrderList:sender
   set currentSelection to sender's titleOfSelectedItem() as text
   set orderChoosen to item 1 of my list_positions(orderList, currentSelection)
   my printAreaPopop's removeAllItems()
   my (printAreaPopop's addItemsWithTitles:(item orderChoosen of listOfTabLists))
end setOrderList:

on list_positions(this_list, this_item)
   set the offset_list to {}
   repeat with i from 1 to the count of this_list
       if item i of this_list is this_item then
           set the end of the offset_list to i
       end if
   end repeat
   return the offset_list
end list_positions

Offline

 

#7 2017-03-15 06:18:37 pm

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

Re: Change elements dynamically using Shane's Dialog Toolkit?

You have a couple of simple problems. First, you use "my thePath", implying thePath is a property, but you don't declare it as such. I think you need to, and add the "my" when you first use it. The second issue is syntax:

Applescript:

my thePath's setStringValue:"Updated String"


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

Offline

 

#8 2017-03-15 07:39:15 pm

t.spoon
Member
From: BFE, Massachusetts
Registered: 2013-01-12
Posts: 130

Re: Change elements dynamically using Shane's Dialog Toolkit?

Does the use of "my" imply it's a property? I thought it just allowed you to access top-level script objects from inside a handler.

Applescript:

set bob to "some text"
do_something()

on do_something()
   display dialog my bob
end do_something

works.

I had made printAreaPopop a property per your suggestion, but in modifying the script I had accidentally deleted the property declaration, and then later was surprised to see it still worked.

Simply changing the syntax to what you just provided:

my thePath's setStringValue:"Updated String"

made it work.

So thank you again, I certainly should have noticed that error.

I'm pretty sure I've got all the basic functionality I'm going to need now to make it all work,

- Tom.

Offline

 

#9 2017-03-15 07:48:57 pm

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

Re: Change elements dynamically using Shane's Dialog Toolkit?

t.spoon wrote:

Does the use of "my" imply it's a property? I thought it just allowed you to access top-level script objects from inside a handler.

Ignore that. I was mis-reading your code and thinking it was defined within a handler.

Simply changing the syntax to what you just provided:

my thePath's setStringValue:"Updated String"

made it work.

FWIW, if you had Console running with your eariler version, you would have seen entries like this:

Applescript:

-[NSTextField setStringValue]: unrecognized selector sent to instance 0x7f88c0bc6af0

That tells you there's something wrong with the method you're using.

I'm pretty sure I've got all the basic functionality I'm going to need now to make it all work

Great.


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

Offline

 

#10 2017-03-15 08:28:24 pm

t.spoon
Member
From: BFE, Massachusetts
Registered: 2013-01-12
Posts: 130

Re: Change elements dynamically using Shane's Dialog Toolkit?

I did have console running and saw the message. I'd used it's output to debug the 1st part. But I didn't know what to make out of that message in terms of knowing how to fix my code.

Thanks for the tip re: console,

- Tom.

Offline

 

#11 2017-04-18 05:47:53 pm

t.spoon
Member
From: BFE, Massachusetts
Registered: 2013-01-12
Posts: 130

Re: Change elements dynamically using Shane's Dialog Toolkit?

My dialog is huge and complicated now, and overwhelmingly working really well.

This is non-essential, it would be possible for me to compile an extensive list of what people might want to type in this situation, and use a pop-up instead of a text field.

But it would be nice if I could use the text-field...

At the bottom of my dialog I've got a non-editable, script-updated text field showing information on what's going to happen when the user clicks "OK" based on what they've input.

It's all working great except with one user-modifiable text-field. I can only get it to update the information at the bottom to include the contents of the text field iff the user changes a popup after changing the text field. This will be confusing to the user, that the information shown at the bottom will not reflect the text they've input unless they change [any unrelated UI element in the dialog] after filling in the text field.

Here's a simplified script showing the problem:

(the real script just has way too many dependencies to post / modify)

Applescript:

use AppleScript version "2.4" -- Yosemite (10.10) or later
use framework "Foundation"
use scripting additions
use script "Dialog Toolkit" version "2.0"


property fileNameField : {}

set {aPopup, theTop} to create popup {"1st Item", "2nd Item"} left inset 0 bottom 0 popup width 200

set {thePathLabel, theTop} to create label "Modified Text" left inset 0 bottom (theTop + 10) max width 400 aligns left without multiline

set {fileNameField, fileNameLabel, theTop, fieldLeft} to create side labeled field "" placeholder text "Enter Text Here" left inset 0 bottom (theTop + 10) total width 400 label text "OPTIONAL - Edit Print Area Name:" field left 0

fileNameField's setTarget:me
fileNameField's setAction:"changePathText:"

aPopup's setTarget:me
aPopup's setAction:"changePathText:"

set {buttonName, suppressedState, controlsResults} to display enhanced alert "Test" message "" as informational alert buttons {"Cancel", "OK"} giving up after 120 acc view width 600 acc view height (theTop + 10) acc view controls {fileNameField, thePathLabel, aPopup} without suppression

on changePathText:sender
   set fileNameAddendum to fileNameField's stringValue()
   my (thePathLabel's setStringValue:fileNameAddendum)
end changePathText:

Inputting text into the text field does not change the value shown in the "thePathLabel" field. However, changing the popup after modifying the text field does change "thePathLabel." So it's reading and writing the values OK, it just appears  that the lines:

Applescript:

fileNameField's setTarget:me
fileNameField's setAction:"changePathText:"

Aren't sufficient to detect a change to the text field and trigger the handler.

I was looking at this:
http://stackoverflow.com/questions/7010 … ange-event
and this:
http://stackoverflow.com/questions/1738 … om-control

But was unable to figure out how to incorporate them into Applescript. Any help?

While I'm here:

When using my script, Console frequently logs:

This application is modifying the autolayout engine from a background thread after the engine was accessed from the main thread. This can lead to engine corruption and weird crashes.

Should I be worried about this / is there a way to fix it?

Also, I'm not quite done with the dialog yet, but so far in testing it works fine when run from Script Debugger or Script Editor, but if I put it on a FastScripts key command then FastScripts just crashes. I haven't done anything to investigate that myself yet, and if I can't solve it, I can address it in a separate post (or ask Daniel), but thought I'd throw it out here in case there's some easy thing "everybody knows" like "when running ASObjC from FastScripts, you have to do [x] to keep it from crashing."

Thanks,

Tom.

Last edited by t.spoon (2017-04-18 06:27:42 pm)

Offline

 

#12 2017-04-18 08:19:32 pm

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

Re: Change elements dynamically using Shane's Dialog Toolkit?

t.spoon wrote:

It's all working great except with one user-modifiable text-field. I can only get it to update the information at the bottom to include the contents of the text field iff the user changes a popup after changing the text field.

Actually, it's updated when the user leaves the text field -- the action is called when the user finishes editing.

To have it update each time the text changes, you can use a text field delegate method. So replace this:

Applescript:

fileNameField's setTarget:me
fileNameField's setAction:"changePathText:"

with this:

Applescript:

fileNameField's setDelegate:me

And then add this handler:

Applescript:

on controlTextDidChange:notif
   set fileNameAddendum to fileNameField's stringValue()
   my (thePathLabel's setStringValue:fileNameAddendum)
end controlTextDidChange:

Anything that refers to UI-prefixed classes instead of NS-prefixed classes is for iOS, not macOS. There are similarities, but also big differences.

When using my script, Console frequently logs:

This application is modifying the autolayout engine from a background thread after the engine was accessed from the main thread. This can lead to engine corruption and weird crashes.

Should I be worried about this / is there a way to fix it?

This should only happen when you're testing. Strictly speaking I'm playing a bit loose with threading, but it shouldn't matter. The solution makes things a lot more complicated.

if I put it on a FastScripts key command then FastScripts just crashes.

That shouldn't happen. Please email me the actual script and crash info.


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

Offline

 

#13 Yesterday 05:18:47 pm

t.spoon
Member
From: BFE, Massachusetts
Registered: 2013-01-12
Posts: 130

Re: Change elements dynamically using Shane's Dialog Toolkit?

Thanks once again.

The text-updating is working brilliantly now. I rewrote a lot of what I had now that I've wrapped my head around Dialog Toolkit and the ASObjC components better.

Anybody:

On the script, it keeps getting much better, but I keep coming up with some additional case I have trouble solving.

This example shows it working great:

Applescript:

use AppleScript version "2.4" -- Yosemite (10.10) or later
use framework "Foundation"
use scripting additions
use script "Dialog Toolkit" version "2.0"


property ordersNmethods : {}

set ordersNmethods to {theOrders:{"Please Make a Selection", "Order Number 1, Production Method 2", "Order Number 2, Production Method 5"}, theMethods:{missing value, 2, 5}}

set {methodPopup, methodPopupLabel, theTop, matrixLeft} to create labeled popup {"1 - Some Method", "2 - Another Method", "3 - Still More Methods", "4 - The Rhythm Method", "5 - Methodical"} left inset 0 bottom 0 popup width 200 max width 400 label text "Override Method" popup left 0

set {orderPopup, orderPopupLabel, theTop, matrixLeft} to create labeled popup (theOrders of ordersNmethods) left inset 0 bottom (theTop + 20) popup width 200 max width 400 label text "Choose an Order" popup left 0

orderPopup's setTarget:me
orderPopup's setAction:"setMethod:"

set {buttonName, suppressedState, controlsResults} to display enhanced alert "Test" message "" as informational alert buttons {"Cancel", "OK"} giving up after 120 acc view width 700 acc view height (theTop + 10) acc view controls {methodPopup, orderPopup} without suppression

on setMethod:sender
   set selectedOrderIndex to (my orderPopup's indexOfSelectedItem() as integer) + 1
   set orderMethod to item selectedOrderIndex of theMethods of ordersNmethods
   my (methodPopup's selectItemAtIndex:(orderMethod - 1))
end setMethod:

So in the dialog, the user needs to select which order they're working on. They occasionally need to override the default "production method" set in the system. I need the default production method field to populate with the default, and it's easy to do that when the user makes a selection for which order they're working on. So that's great.

The problem is that sometimes there's only one option for what order they could conceivably be working on. That happens a lot. In that case, I don't want the options on the top popup to start with "Please Make a Selection" like they do above, I just want that popup to be pre-selected with the only option so they don't have to waste time making a selection off a list with one option.

But I still need the production method field to update to the method of the single option showing in the first popup.

So when the data looks like this:

Applescript:

use AppleScript version "2.4" -- Yosemite (10.10) or later
use framework "Foundation"
use scripting additions
use script "Dialog Toolkit" version "2.0"


property ordersNmethods : {}

set ordersNmethods to {theOrders:{"Order Number 1, Production Method 2"}, theMethods:{2}}

set {methodPopup, methodPopupLabel, theTop, matrixLeft} to create labeled popup {"1 - Some Method", "2 - Another Method", "3 - Still More Methods", "4 - The Rhythm Method", "5 - Methodical"} left inset 0 bottom 0 popup width 200 max width 400 label text "Override Method" popup left 0

set {orderPopup, orderPopupLabel, theTop, matrixLeft} to create labeled popup (theOrders of ordersNmethods) left inset 0 bottom (theTop + 20) popup width 200 max width 400 label text "Choose an Order" popup left 0

orderPopup's setTarget:me
orderPopup's setAction:"setMethod:"

set {buttonName, suppressedState, controlsResults} to display enhanced alert "Test" message "" as informational alert buttons {"Cancel", "OK"} giving up after 120 acc view width 700 acc view height (theTop + 10) acc view controls {methodPopup, orderPopup} without suppression

on setMethod:sender
   set selectedOrderIndex to (my orderPopup's indexOfSelectedItem() as integer) + 1
   set orderMethod to item selectedOrderIndex of theMethods of ordersNmethods
   my (methodPopup's selectItemAtIndex:(orderMethod - 1))
end setMethod:

I need the second popop ("Override Method") to come up with the method of the single, default order already selected.

The only way I could figure out how to do this is: when there's only a single order choice, then reorder the Production Method list so the correct choice is at the top of the list.

But this isn't a good option, because the users are used to these appearing in a certain order everywhere, and people are going to make incorrect selections when they're out-of-order.

I'm concerned that this possibility is excluded with Dialog Toolkit because it looks to me like a "selectItemAtIndex:" or "selectItemWithTitle:" would need to be called at the time of Dialog Toolkit's "display enhanced alert" call - Dialog Toolkit would need to accept a "default option" argument as a parameter of "create labeled popup." Applescript, of course, comes to a stop from when it calls "display enhanced alert" until the dialog is dismissed, unless an option is chosen in the dialog to trigger a handler.

I can possibly do something clunky like, before calling "display enhanced alert" call a "selectItemAtIndex:" inside a delay with an "ignoring application responses," but that sounds like it's asking for trouble. Especially since my real dialog retrieves information off the web to populate the dialog, introducing a large variation in the time for the dialog to load.

Any ideas?


Shane: I PM'd you a link to download the whole thing to take a look at the FastScripts issue.

I've had three modes of failure there:

At first, it was just crashing - nothing would happen, and if I clicked on the Fastscripts widget in the menu bar the menu would't come down, no Fastscripts scripts would run, and I'd have to force quit and relaunch it to get it to do anything.

Then it switched to opening a "Scripting Error" window that just says "Error Number: -1

Unknown error."

And at least once, it gave me an error that said something like ["Unable to use" or "Unable to load"] "framework "Foundation"" That's the only remotely helpful error I've received, although it still seems like an odd error to me.

Offline

 

#14 Yesterday 07:21:35 pm

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

Re: Change elements dynamically using Shane's Dialog Toolkit?

t.spoon wrote:

Any ideas?

It sounds like you need to make a custom version of Dialog Toolkit that allows you to set the selected popup item.

Shane: I PM'd you a link to download the whole thing to take a look at the FastScripts issue.

It's behaving for me. One thing to keep in mind with FastScripts:

* It uses a single instance of AppleScript. This means that once it loads a lib, if you ever modify that lib, you need to restart FastScripts.


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

Offline

 

#15 Yesterday 08:11:20 pm

t.spoon
Member
From: BFE, Massachusetts
Registered: 2013-01-12
Posts: 130

Re: Change elements dynamically using Shane's Dialog Toolkit?

Well that's fascinating.

I had restarted FastScripts plenty of times. I still get the crashes.

So... either it was a system difference, or it was the one change I made to send the script to  you - I commented out that handler that gets information on the open orders from our in-house CRM/ERP system in Chrome, and just made the function return dummy values.

So... it's that function. Fastscripts runs the version I sent you just fine. It crashes when I un-comment out that dialog and have it get the info from Chrome.

So clearly, it's not related to Dialog Toolkit.

Since it runs fine from Script Debugger and Script Editor, I'll bring it up with Daniel.

Is editing Dialog Toolkit to accept this as straight-forward as I'm thinking? Add a "default selection" term to the handler, and feed it to a "selectItemAtIndex:" argument?

If it's OK with you for me to dig into Dialog Toolkit and use a modified version, I'd be happy to give that a shot.

Thanks again,

- Tom.

Last edited by t.spoon (Yesterday 08:11:50 pm)

Offline

 

#16 Yesterday 09:08:38 pm

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

Re: Change elements dynamically using Shane's Dialog Toolkit?

t.spoon wrote:

If it's OK with you for me to dig into Dialog Toolkit and use a modified version, I'd be happy to give that a shot.

Of course! Probably the safest way is to add a whole new handler, thus keeping compatibility with any existing stuff. And if it's only for your use, you can make it a normal handler without terminology.


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

Offline

 

Board footer

Powered by FluxBB

[ Generated in 0.148 seconds, 10 queries executed ]

RSS (new topics) RSS (active topics)