I've placed them in my "Keyboard Maestro" macro group. All assume v10 of KM (mainly because the main macro is a subroutine).
The macros are shown collapsed as they rely on image recognition for the Add/Remove buttons in the Inspector - and it might otherwise find those buttons in the macro itself. Take care when running these macros if you have any Add/Remove buttons visible in the currently-visible macro, or those buttons may be pressed in it instead ... with unforeseen consequences!
UPDATE: Please use the safer, alternative form of macro 2 below which doesn't suffer from this. Macro 3 could also be re-written to use AppleScript UI scripting, but I haven't got there yet!
1. Open (and set focus to) the Value Inspector
This just opens the Value Inspector (or closes and re-opens it) so that it is certain to have focus. This sometimes fails for me at the moment.
3. Show set of variables in Value Inspector
This is the main macro (well, subroutine) which can be passed a comma-separated list of variables to display (the same format that the AccessedVariables token uses). It can optionally remove all other entries in the Inspector first, using the second macro above.
After a cursory look at your macro set I really like it! I can foresee myself using it quite a bit for debugging. Thanks again for taking the time to come up with this.
I hope you don't mind, but I wanted to share an alternative method of clearing any existing items in the Value Inspector using GUI AppleScript. It basically gets the description of button 1 on the first row, and if it's "Delete Button" then it runs the next set of actions which are to click that button, and repeat the initial script to see if there are still any "Delete Button" buttons. Once the initial script returns false (indicating button 1 is add, and not delete), then the macro finishes.
This way you don't need the Value Inspector to be in focus, which makes it possible to simplify the Open (and set focus to) the Value Inspector macro which I have also included here.
I haven't had time to look at the other two macros but hopefully I will this evening after work and (shudder) my dental appointment
Thanks, Chris - that looks like a much more reliable solution
I thought about using GUI scripting, but couldn't use UI Browser to look at the Value Inspector window, as it disappears when KM loses focus! How did you work out the window/button elements?
I just barely learned it this year after over 3 years of using Keyboard Maestro
Even better! I don't know why I didn’t write it this way... since I've written other scripts like that. My coffee apparently hadn't kicked in haha. It works a lot faster than my method too, very nice!
I feel I should convert the Show set of variables in Value Inspector macro (which should probably be called Add variables to Value Inspector) to UI AppleScript now - but I'm not sure how to select "Variable" from the pop-up button after clicking the last even-numbered button (or the first button if there's only one). Perhaps someone else can scratch that itch
I've been working on this off and on today and I'm kind of stumped. Have you made any progress?
EDIT: This is what I came up with BUT... because of what I believe are accessibility issues (as documented here) there is a significant delay (about 6 seconds) between clicking the add button and clicking variable...adding ignoring application responses does not make a difference unfortunately.
----------------------------------------------------------
# Author: Chris Thomerson
#
# Current Version: 1.0
# Version History: 1.0 (Initial script)
#
# Created: Thursday, December 2, 2021
# Modified: Thursday, December 2, 2021
# macOS: 11.6.1 (Big Sur)
#
# Notes:
# I claim no responsibility nor guarantee compatibility
# As with any kind of custom scripts, these must be tested thoroughly on each person's device
# May be used and distributed freely
----------------------------------------------------------
tell application "System Events"
tell application process "Keyboard Maestro"
-- ignoring application responses
click (last button whose role is "AXButton" and description is "Add Button") of scroll area 1 of window "Value Inspector"
click menu item "Variable" of menu 1 of scroll area 1 of window "Value Inspector"
-- end ignoring
end tell
end tell
This is Apple's long time buggy b.s. They deserve much invective for never fixing it, so please complain to Feedback - macOS - Apple
The best solution currently is to have Keyboard Maestro click the button and let System Events select the menu item.
I've encapsulated all the Keyboard Maestro actions in the AppleScript.
I have not written the code to handle the macro variable names; I leave that to the user.
-Chris
--------------------------------------------------------
# Auth: Christopher Stone
# dCre: 2021/12/02 19:08
# dMod: 2021/12/02 19:25
# Appl: Keyboard Maestro, Keyboard Maestro Engine, System Events
# Task: Populate the Variable Value Inspector Window
# Libs: None
# Osax: None
# Tags: @Applescript, @Script, @Keyboard_Maestro, @Keyboard_Maestro_Engine, @System_Events, @Populate, @Variable, @Value, @Inspector, @Window
--------------------------------------------------------
tell application "System Events"
tell application process "Keyboard Maestro"
tell scroll area 1 of window "Value Inspector"
tell (last button whose role is "AXButton" and description is "Add Button")
set {x, y} to its position
end tell
end tell
end tell
end tell
# Position Offsets
set x to x + 15
set y to y + 15
# For zeroing in on the location.
set kmMoveAction to text 2 thru -1 of "
<dict>
<key>Action</key>
<string>Move</string>
<key>ActionUID</key>
<integer>97334</integer>
<key>Button</key>
<integer>0</integer>
<key>ClickCount</key>
<integer>0</integer>
<key>DisplayMatches</key>
<false/>
<key>DragHorizontalPosition</key>
<string>0</string>
<key>DragVerticalPosition</key>
<string>0</string>
<key>Fuzz</key>
<integer>15</integer>
<key>HorizontalPositionExpression</key>
<string>" & x & "</string>
<key>MacroActionType</key>
<string>MouseMoveAndClick</string>
<key>Modifiers</key>
<integer>0</integer>
<key>MouseDrag</key>
<string>None</string>
<key>Relative</key>
<string>Absolute</string>
<key>RelativeCorner</key>
<string>TopLeft</string>
<key>RestoreMouseLocation</key>
<false/>
<key>VerticalPositionExpression</key>
<string>" & y & "</string>
</dict>
"
set kmClickAction to text 2 thru -1 of "
<dict>
<key>Action</key>
<string>Click</string>
<key>ActionUID</key>
<integer>97347</integer>
<key>Button</key>
<integer>0</integer>
<key>ClickCount</key>
<integer>1</integer>
<key>DisplayMatches</key>
<false/>
<key>DragHorizontalPosition</key>
<string>0</string>
<key>DragVerticalPosition</key>
<string>0</string>
<key>Fuzz</key>
<integer>15</integer>
<key>HorizontalPositionExpression</key>
<string>" & x & "</string>
<key>MacroActionType</key>
<string>MouseMoveAndClick</string>
<key>Modifiers</key>
<integer>0</integer>
<key>MouseDrag</key>
<string>None</string>
<key>Relative</key>
<string>Absolute</string>
<key>RelativeCorner</key>
<string>TopLeft</string>
<key>RestoreMouseLocation</key>
<true/>
<key>VerticalPositionExpression</key>
<string>" & y & "</string>
</dict>
"
set kmTypeReturn to text 2 thru -1 of "
<dict>
<key>ActionUID</key>
<integer>97361</integer>
<key>KeyCode</key>
<integer>36</integer>
<key>MacroActionType</key>
<string>SimulateKeystroke</string>
<key>Modifiers</key>
<integer>0</integer>
<key>ReleaseAll</key>
<false/>
<key>TargetApplication</key>
<dict/>
<key>TargetingType</key>
<string>Front</string>
</dict>
"
# Use Keyboard Maestro to Click the + Button.
tell application "Keyboard Maestro Engine"
do script kmClickAction
do script kmTypeReturn
# do script kmMoveAction -- for zeroing in on the location.
end tell
tell application "System Events"
tell application process "Keyboard Maestro"
tell window "Value Inspector"
tell scroll area 1
tell menu 1
# tell menu item "Variable" -- Select New Variable.
# perform action "AXPress"
# end tell
end tell
tell last text field
set its value to "VARIABLE_NAME"
end tell
end tell
end tell
end tell
end tell
--------------------------------------------------------
Thanks for chiming in and confirming it's an issue with Apple!
Some of your AppleScript is beyond my comprehension this late in the day, but it did help me think of other ways of accomplishing this. I'll take a look at it again tomorrow when I'm hopefully a little more lucid haha.
@coordinated here's something that works for me quite reliably, based on @ccstone's post above. Basically it gets the coordinates of the button and then uses Keyboard Maestro to click it. The rest is pretty much how you left it.
One thing I did notice when running it in a macro that quite a few variables (15 to be exact), is if the Value Inspector is not large enough to display 15 lines, it will only populate as many variables as the window has room for. After that, it ends up just replacing the last line with each new variable. But it's progress at least!
EDIT: Made a few tweaks: returning mouse to original location and cleaning up variables at the end of the macro. Let me know what you think.
EDIT 2: If you change the tell last button line to tell first button, it resolves the issue I mentioned earlier. The variables might not be in the preferred order, but the VI size is at least irrelevant.