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