I am testing PreFab’s UI Action application in order to get at information in the contextual menu–in this case, a spelling correction. According to PreFab’s documentation: “Your UI Action scripts can get the role, role description and subrole of a UI element using standard GUI Scripting techniques.” Does anybody know how I might get at the AXMenuItem roll/subroll as suggested?
Let me be more specific: I have been toiling with PreFab’s UI Actions tool in an attempt to get at the so-called title of the element when I employ AppleSpell thru the contextual menu. The UI Browser shows that this is the spelling word correction which is what I want. I’ve tried the following but it produces an error:
tell current UI action --the one refered to in declared UI action object?
set thisValue to affected UI element
return roll of thisValue
Also, I find that the path to the selected menu item has a “missmatch” that prevents me from getting the
value. Is their a way to bypass this apparent dead end?
The problem here is that using the UI Browser is highly experimental, and different for different apps. Since we don’t have whatever app you’re struggling with (and so cannot try ourselves), I’m afraid you aren’t going to get very enlightened answers to a problem stated in rather general terms.
Adam: thanks for feedback. Reading my post this morning, I see how unhelpful it is. Perhaps if I re-phrase the problem it might help.
I am using PreFabs UI Actions tool to attach an AppleScript to an application–Text Edit–in this case. When a user highlights a spelling error and right-clicks/control-clicks to choose one of AppleSpell’s suggested spelling words in the contextual menu, I wish for UI Actions to trigger an AppleScript to capture the chosen spelling replacement. By using PreFabs other tool, UI Browser, I see that one of the accessibility API items that the tool reports under the Element heading, ‘Title’, shows the replacement spelling correction. Furthermore, the spelling correction is also shown as the last of the items within the accessibility hierarchy of the Element listing. Unfortunately, one of the items within this hierarchy chain, the one above the spelling word being selected, shows a “Missmatch” element. This effectively keeps me from writing an AppleScript address to the spelling word despite it’s being shown in the UI browser. So my question is two-fold: is there a way to get the content of the Element Title? It would seem that there might be, since PreFab writes: “Your UI Action scripts can get the role, role description and subrole of a UI element using standard GUI Scripting techniques.” And if not, is there a way to get a path to the menu item element despite the apparent blockage caused by the [Missmatch] element. For example, the following path would capture the spelling word if not for the [Missmatch] that acts like a broken link within the path chain:
tell process "TextEdit"
set spellingCorrection to value of menu item of menu item [Missmatch] of text area 1 of scroll area 1 of front window
end tell
OK. I realize this description is unwieldy so I don’t expect much in the way of help. Nevertheless, there is a chance someone out there has experience with these PreFab tools. Also, I am presenting a link to this blog page to PreFab’s technical support staff; perhaps they might have a solution.
Here is the way I grab infos from UI elements:
tell application "TextEdit" to activate
tell application "System Events" to tell process "TextEdit"
tell menu bar 1
get name of every menu bar item
--{"Apple", "TextEdit", "Fichier", "Édition", "Format", "Fenêtre", "Aide"}
tell menu bar item 4 to tell menu 1
get name of every menu item
-- {"Annuler", "Rétablir", missing value, "Couper", "Copier", "Coller", "Coller le style et l'appliquer", "Supprimer", "Compléter", "Tout sélectionner", missing value, "Insérer", missing value, "Rechercher", "Orthographe", "Parole", missing value, "Caractères spéciaux."}
tell menu item 15 to tell menu 1
get name of every menu item
--{"Orthographe.", "Vérifier l'orthographe", "Vérifier l'orthographe lors de la frappe"}
click menu item 2
delay 10
end tell
end tell
end tell
-- set spellingCorrection to value of menu item of menu item [Missmatch] of text area 1 of scroll area 1 of front window
end tell
Are you sure that you didn’t type three period characters when the menu item ends with the ellipsis (.) char ?
Yvan KOENIG (from FRANCE dimanche 10 août 2008 19:55:12)
Yvan: thanks for your UI suggestion–it works great. My difficulty, however, lies with trying to capture information within the contextual menu–when you right-click or control-click upon a highlighted spelling word. I wish to capture the spelling selection that the user then selects. Your script initiates the conventional spell checker menu item within TextEdit.
problem: the path to the selected menu item has a “missmatch” that
prevents me from getting the value. Is their a way to bypass this apparent dead end?
Here’s what Bill Cheeseman has to say about the matter:
… Still, as a matter of curiosity, I wonder how I might write an AppleScript that would
capture the “roll,” “sub-roll,” and similar auxiliary information
used by UI Actions for future use.
activate application "Finder"
tell application "System Events"
tell process "Finder"
open (path to startup disk)
tell window 1
set r to role
set sr to subrole
end tell
display dialog "Role \"" & r & "\; " & subrole & sr & "\""
end tell
end tell
Notice that the correct spelling is “role”, not “roll”.
I really don’t understand.
AppleSpell is not a tool reachable thru the contextual menu, it’s the system’s service which calls the Apple Spell Checker.
Assuming that you are using this checker.
I get the wanted item (under 10.4) with:
tell application "TextEdit" to activate
tell application "System Events" to tell process "TextEdit"
get value of text field 1 of window 1
end tell
If you are using an alternate product, it would be useful to give its exact name so I would be able to download and test it if it’s a free product.
Yvan KOENIG (from FRANCE mercredi 13 août 2008 18:06:31)
Yvab:
When I referred to AppleSpell access through the contextual menu, I meant that when you highlight a word in any Apple application with spell checking capability, the user can select a spelling correction listed at the top of the drop-down menu (which must be provided by the AppleSpell system service you referred to). In other words, by control-clicking on the keyboard, or right-clicking with the mouse over the underlined spelling error, the user can select a spelling correction listed within this drop-down menu. While your previously posted script finds the underlined spelling error, I need my script to act at the moment the user makes a correction–hence the need for Mr. Cheeseman’s UI Actions tool that can detect when the contol key or mouse click occurs (a trial version of UI Actions can be downloaded for free).
Your solution does provide a useful method for exhaustively collecting spelling errors in TextEdit and I may find it useful yet. I hope I am not overlooking something useful and obvious in your proposed solutions still. Please let me know if so. By the way, I can’t get your last script sample to work on my machine, though I gather it copies the document text, which I can already do.
Thank you for your help.