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.
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)
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>
"