MACRO: Scroll to Top or Bottom of Macro, v3.0

PURPOSE

When a macro is open in the Keyboard Maestro editor, this macro can be used to scroll to the top or bottom of the macro. When the macro scrolls to the bottom, the last macro action is selected. When the macro scrolls to the top, the first macro action is selected or alternatively the macro icon image well is selected.


Hot Keys

Hot Key Behavior
⌥⌘↓ Scroll to the bottom and select the last action
⌥⌘↑ Scroll to the top and select the first action
⌃⌥⌘↑ Scroll to the top and select the macro icon image well

TESTED WITH

• Keyboard Maestro 11.0.3
• Sequoia 15.1 (24B5055e)/MacBookPro18,2
• Mojave 10.14.16/Macmini6,2
• High Sierra 10.13.6/iMac11,1445


VERSION HISTORY

( expand / collapse )

1.0 - initial version

2.0

a) For scrolling to the top (with or without selecting the macro icon image well), simplified the logic using information shared by @NaOH.

b) Since the scrolling to the top logic was changed, the PREREQUISITES are only required when scrolling to the bottom.

3.0

a) For scrolling to the bottom, simplified the logic using an AppleScript approach by @Nige_S.

b) The above change eliminates two earlier requirements: 1) The System Setting (or System Preference) Show scroll bars had to be set to Always, and 2) The entire Keyboard Maestro editor had to be visible on the mac display.



Download: Scroll to Top or Bottom of Macro.kmmacros (18 KB)

Macro-Image


Macro-Notes
  • Macros are always disabled when imported into the Keyboard Maestro Editor.
    • The user must ensure the macro is enabled.
    • The user must also ensure the macro's parent macro-group is enabled.

System Information
  • macOS 15.1 (24B5055e) PRE-RELEASE SEED SOFTWARE
  • Keyboard Maestro v11.0.3
2 Likes

I've updated the OP with Version 2.0 of Scroll to Top or Bottom of Macro:

  • For scrolling to the top (with or without selecting the macro icon image well), simplified the logic using information shared by @NaOH.

  • Since the scrolling to the top logic was changed, the PREREQUISITES are only required when scrolling to the bottom.

I've updated the OP with Version 3.0 of Scroll to Top or Bottom of Macro:

  • For scrolling to the bottom, simplified the logic using an AppleScript approach by @Nige_S.

  • The above change eliminates two earlier requirements: 1) The System Setting (or System Preference) Show scroll bars had to be set to Always, and 2) The entire Keyboard Maestro editor had to be visible on the mac display.

Since posting Version 3.0 I have noticed that the scroll down AppleScript (largely supplied by @Nige_S) occasionally fails. The symptom will be that the last action gets selected but the editor does not scroll to the very bottom. I've not been able to determine a method to reproduce the error. But here's the error from Engine.log:

2024-10-01 13:42:00 Action 16249560 failed: Execute an AppleScript failed with script error: text-script:592:597: execution error: System Events got an error: Can’t get group 6 of window 1 of process "Keyboard Maestro". Invalid index. (-1719)

Also, I've not been able to find steps to recover proper operation. I've tried stopping and restarting the Keyboard Maestro editor (and Engine), and that hasn't necessarily worked. I do know, however, that the AppleScript will sometimes resume normally operation before I log out and back in.

Here's the AppleScript (the bad parts are mine; the good stuff is from @Nige_S):

try
	tell application "Keyboard Maestro"
		set selectedMacroList to selected macros
		if length of selectedMacroList = 1 then
			set currentMacro to item 1 of selectedMacroList
			select the last action of the currentMacro
		end if
	end tell
	tell application "System Events"
		tell process "Keyboard Maestro"
			if name of window 1 is "New Action" then
				set winIndex to 2
			else
				set winIndex to 1
			end if
			tell window winIndex
				tell group 6
					tell splitter group 1
						tell scroll area 3
							tell scroll bar 1
								-- moves thumb to top(0)/bottom(1)
								set value to 1
							end tell
						end tell
					end tell
				end tell
			end tell
		end tell
	end tell
end try

Has anyone else observed this issue?

Not a solution to your AS problem but this (cobbled from several examples on this topic) has been working for me with/without scroll bars on both old Intel and new Apple Silicon. It's also under 6K.

In addition to top and bottom and third option (left arrow) goes to the middle:

Scroll Macro (v11.0.3)

Scroll.kmmacros (5.6 KB)

1 Like

That's the same error we were getting when the "New Action" pane was open (before the if block was added), suggesting that your Editor window isn't window 1. To troubleshoot, try wrapping tell group 6 and below in an try block, displaying the window 1 name on error:

...
try
   tell group 6
      tell splitter group 1
          ...
      end tell
   end tell
on error
   display dialog (name of window 1)
end try

A bit old-school, but it might give you a clue.

1 Like

Thanks, @Nige_S. I've give it a try. I don't see the issue often, thus it might take some time.

Thanks, @mrpasini. When I observe this issue again, I'll give your macro a try. (Based on your approach, I'm guessing it might fail too.)