Toggling Debugger Window via Applescript, Macro Will Not Proceed After Window Is Open

Howdy folks,

Calling on the AppleScript gurus here to help me out with something I’m working on. Basically, I want to toggle the debugger window via AppleScript, and then position it via that same AppleScript. Sounds simple, except that when the debugger window appears, it automatically pauses all macros execution, including it’s own.

Normally, this is resolved by placing the Debugger Continue This Macro immediately after the Debugger Toggle action, and I can confirm that it works as intended in a normal macro. For example, in my “this works” sample macro below, the notification is shown even after the debugger window appears, indicating that the macro continued and finished it’s execution.

However, I wrote an AppleScript that uses those two actions’ XML to trigger the debugger window and then proceed with the calling macro (see the full AppleScript below). When I execute this AppleScript from Script Debugger, it works as expected. But when I execute this AppleScript from Keyboard Maestro, the debugger window appears and is positioned, but the debugger window pauses the macro that called the AppleScript, even though the Debugger Continue This Macro action is part of the actions that the AppleScript compiled and supposedly executed, and even though it appears that the AppleScript exited successfully. I’m at a loss as to why that’s happening. :confused:

Perhaps there’s something out of order with my AppleScript, or there’s some other nuance to the debugger actions that I’m missing. So if anybody has any ideas, I’m all ears. Thanks in advance!

03)Toggle Debugger (for testing - this works).kmmacros (2.5 KB)

03)Toggle Debugger (for testing - this doesn’t work).kmmacros (4.8 KB)

Working Macro Screenshot (click to expand/collapse)

Non-Working Macro Screenshot (click to expand/collapse)

AppleScript (click to expand/collapse)
set xPos to 20 as integer
set yPos to 50 as integer
set xSize to 750 as integer
set ySize to 450 as integer
set delayInteger to 0.2
set theWindow to "Keyboard Maestro Debugger"

# Determine if opening or closing debugger window
tell application "Keyboard Maestro Engine"
	if window "Keyboard Maestro Debugger" exists then
		set openingDebugger to "False"
	else
		set openingDebugger to "True"
	end if
end tell

# Open debugger window and proceed with macro
tell application "Keyboard Maestro"
	set macroAction to my kmToggleDebuggerScript(debuggerActionsXML)
end tell

# position window if opening and working
if openingDebugger is "True" then
	tell application "System Events"
		tell application process "Keyboard Maestro Engine"
			# wait for window to appear
			repeat until window theWindow exists
				delay delayInteger
			end repeat
			tell window theWindow
				# set its size
				repeat until its size is {xSize, ySize}
					set its size to {xSize, ySize}
					delay delayInteger
				end repeat
				# set its position
				repeat until its position is {xPos, yPos}
					set its position to {xPos, yPos}
					delay delayInteger
				end repeat
			end tell
		end tell
	end tell
end if

--------------------------------------------------------
--» HANDLERS
--------------------------------------------------------
on kmToggleDebuggerScript(theScript)
	tell application "Keyboard Maestro Engine"
		do script theScript
	end tell
end kmToggleDebuggerScript

--------------------------------------------------------
--» PROPERTIES
--------------------------------------------------------
property debuggerActionsXML : "<?xml version=\"1.0\" encoding=\"UTF-8\"?>
<!DOCTYPE plist PUBLIC \"-//Apple//DTD PLIST 1.0//EN\" \"http://www.apple.com/DTDs/PropertyList-1.0.dtd\">
<plist version=\"1.0\">
<array>
	<dict>
		<key>ActionUID</key>
		<integer>15156398</integer>
		<key>DebuggerAction</key>
		<string>Toggle</string>
		<key>IsDisclosed</key>
		<false/>
		<key>MacroActionType</key>
		<string>DebuggerAction</string>
	</dict>
	<dict>
		<key>ActionUID</key>
		<integer>15156399</integer>
		<key>DebuggerAction</key>
		<string>Continue</string>
		<key>IsDisclosed</key>
		<false/>
		<key>MacroActionType</key>
		<string>DebuggerAction</string>
	</dict>
</array>
</plist>
"

I agree! On my list of things to ask for in the future, is this very question:

Why does the "Start Debugger" action work entirely differently from the "Start Debugging" menu item. One pauses all macros; the other does not. I can't find any KM action that duplicates what the "Start Debugger" menu item does.

1 Like

Update: exporting the AppleScript as an app and executing it from KM works as intended, so that’s the method I’ll use for the time being. But if anybody has some insight on my original question I’d still love to hear it because executing it as a scpt file is preferable because it makes it easier to modify it in the future.

Hey, this is working for me, there may be another method I'm sure....
I simply turned the applescript into an app and run it

Edit: eh crap, I can't get it to run consistently. I sometimes get a 'quit or run' dialog and other times it freezes and I have to force quit.
I'll include the applescript I've mangled together from @cdthomer post.

Debugger Start Auto Edit Macro (v11.0.1)

Debugger Start Auto Edit.kmmacros (42 KB)

ignoring application responses
	tell application "Keyboard Maestro Engine"
		do script "F134F392-0B1F-4F8A-A99A-47C4744DFA8C"
		-- or: do script "Debugger Start Auto Edit"
		-- or: do script "F134F392-0B1F-4F8A-A99A-47C4744DFA8C" with parameter "Whatever"
	end tell
end ignoring


set theWindow to "Keyboard Maestro Debugger"
set delayInteger to 0.2
tell application "System Events"
	tell application process "Keyboard Maestro Engine"
		
		# wait for Debugger window to open
		repeat until exists window theWindow
			delay delayInteger
		end repeat
		
		tell window theWindow
			
			# wait for pause checkbox to appear
			repeat until exists checkbox 1
				delay delayInteger
			end repeat
			
			# click to pause macros			
			--click checkbox 1
			
			# wait until the next macro appears in the Debugger window
			repeat until exists button 2 of group 1 of scroll area 1
				delay delayInteger
			end repeat
			
			# click to edit the macro
			click button 2 of group 1 of scroll area 1
			delay delayInteger
			
			try
				click button 1 of group 4 of scroll area 1
				delay delayInteger
			end try
			
			try
				click button 1 of group 3 of scroll area 1
				delay delayInteger
			end try
			
			try
				click button 1 of group 2 of scroll area 1
				delay delayInteger
			end try
			
			# click to cancel the macro
			click button 1 of group 1 of scroll area 1
			delay delayInteger
			
			# click to close the Debugger window
			click button 1
			
		end tell
	end tell
end tell

Only relevant to those of us that have one but...

You could run the script directly from a Stream Deck button.

1 Like

me no got..... =)

That’s the method I ended up using. :+1:t2:

Very true... I have all of my “debugging” macros linked to ⌥⌘L followed by the first character of their name. Thus wanting to be able to run it via KM. But now that you mention it, I think I do have a button dedicated to toggling the debugger window from a long time ago that I forgot about :laughing:

1 Like

There's a version of Stream Deck that's available for an iOS or iPadOS device. In fact, I think there's now a free version that's limited to four buttons. I think the paid version is a $3/month subscription, which I have. (I think the first month is free.) That way I can get up to 64 buttons (I think) on my iPad.

Yes, thanx. Im aware of stream deck. The free version is now 6 buttons.

With all the triggers available via modifier keys, multi-press keys and a 4 button kensington i have more than enough triggers. Palettes either created or conflict are perfect visual aids to macro triggering.

The larger point is that I prefer to work as efficiently as possible and keep my hands on the primary input devices of keyboard and trackball.