Mouse clicks based on position can change depending on screen resolution. Try this basic AppleScript:
It basically clicks all those buttons (and drop down menu) for you, but without relying on coordinates.
The last of the click items has four options, only the first one will execute (never). The other three (alphabetically, group and hierarchically) are disabled with the two dashes preceding them. So this script will disable the menu bar icon. To reenable it, simply put two dashes in front of the "never" line (or delete it completely), and remove the two dashes from whichever option you want (alphabetically, group or hierarchically).
Below is a simple macro that should accomplish disabling the icon. It can be modified much in the way your original macro is to also enable it by making the adjustments to the AppleScript I mentioned above.
EDIT: The revision will now toggle between two options, set from within the AppleScript itself.
----------------------------------------------------------
# Author: Chris Thomerson
# Current Version: 1.3
#
# Version History:
# 1.3 (Simplified some script to make it faster)
# 1.2 (Setting the preferred display option is now done by setting menuOpt to the corresponding number
# 1.1 (Script will now toggle between two options)
# 1.0 (Initial script)
#
# Created: Saturday, November 20, 2021
# Modified: Saturday, November 20, 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
----------------------------------------------------------
----------------------------------------------------------
# List of menu options
# menu item 1 of menu 1 of pop up button 1 of window 1: Never
# menu item 3 of menu 1 of pop up button 1 of window 1: Alphabetically
# menu item 4 of menu 1 of pop up button 1 of window 1: By Group
# menu item 5 of menu 1 of pop up button 1 of window 1: Hierarchically
----------------------------------------------------------
set actDelay to "0.2" -- set the time for the delays between actions
set menuOpt to 4 -- this number corresponds to the option you want from the list above
tell application "System Events"
tell application process "Keyboard Maestro"
click button 1 of toolbar 1 of window 1
delay actDelay
set origOpt to value of pop up button 1 of window 1
click pop up button 1 of window 1 -- click the pop up button
delay actDelay
if origOpt is "Never" then
click menu item menuOpt of menu 1 of pop up button 1 of window 1 -- the option set in the variable above
else
click menu item 1 of menu 1 of pop up button 1 of window 1 -- click on the never option
end if
end tell
end tell
KM- Open Preferences Pane and Toggle Menu Bar Icon (for export).kmmacros (6.2 KB)