Skip to content

Commit 2100a48

Browse files
ThinkOffAppclaude
andcommitted
v0.7.1 — fix silent osascript wake failure
claudemb-wake.sh: bind keystroke to the target process explicitly via 'tell process Claude / set frontmost to true / keystroke' instead of 'tell application System Events to keystroke', which routes to whichever process is frontmost at execution time. The old behavior had a 0.3s race: if Claude.app didn't fully take focus (multi-window, focus contention), keystrokes landed in the user's actual foreground app with NO error logged. @claudemm observed ~10 lost wakes between 21:28-21:44 tonight. Fix: process-targeted keystroke + verify-then-WARN log when finalFront != target. Defense-in-depth, prevents the race instead of catching it after. Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
1 parent 0053294 commit 2100a48

2 files changed

Lines changed: 41 additions & 7 deletions

File tree

‎package.json‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "ide-agent-kit",
3-
"version": "0.7.0",
3+
"version": "0.7.1",
44
"description": "Built for OpenClaw workflows \u2014 ACP session orchestration, room-triggered automation, comment polling, Discord + Moltbook + GitHub connectors, receipts, exec approvals",
55
"type": "module",
66
"bin": {

‎scripts/claudemb-wake.sh‎

Lines changed: 40 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -25,26 +25,60 @@ fi
2525

2626
{
2727
printf "[%s] wake: sending nudge to '%s' app (no focus steal): %s\n" "$(date -u +%FT%TZ)" "$APP_NAME" "$MSG"
28+
# v0.7.1 — process-targeted keystroke + verify-then-log fallback.
29+
#
30+
# The previous version used `tell application "System Events" to keystroke`
31+
# which routes to whichever process is frontmost at the moment of execution.
32+
# If Claude.app didn't fully take focus during the 0.3s delay (multi-window,
33+
# animations, focus contention), the keystroke landed in the user's actual
34+
# foreground app with NO error logged — a silent failure observed by
35+
# @claudemm on 2026-05-02 (~10 nudges sent, ~10 keystrokes lost).
36+
#
37+
# Fix: bind the keystroke target to the process explicitly via
38+
# `tell process "$APP_NAME"`. Then a post-keystroke verify check logs
39+
# WARN when frontmost app != target so we have a paper trail for any
40+
# remaining edge cases.
2841
osascript - "$APP_NAME" "$MSG" <<'APPLESCRIPT'
2942
on run argv
3043
set appName to item 1 of argv
3144
set promptText to item 2 of argv
3245
33-
-- Remember which app has focus
46+
-- Remember which app has focus so we can restore it.
3447
tell application "System Events"
3548
set frontApp to name of first application process whose frontmost is true
3649
end tell
3750
38-
-- Briefly activate Claude, send nudge
51+
-- Activate Claude.app first so it can receive the keystroke routing.
3952
tell application appName to activate
4053
delay 0.3
54+
55+
-- Process-targeted keystroke — bound to Claude's process specifically.
56+
-- Safe even if focus contention briefly puts another app on top.
57+
set sendOk to false
58+
try
59+
tell application "System Events"
60+
tell process appName
61+
set frontmost to true
62+
keystroke promptText
63+
key code 36
64+
end tell
65+
end tell
66+
set sendOk to true
67+
on error errMsg number errNum
68+
log "wake: keystroke failed — " & errNum & " " & errMsg
69+
end try
70+
71+
-- Verify the target app actually had focus at the end. Logged for
72+
-- diagnostics — we don't retry here to avoid double-typing.
4173
tell application "System Events"
42-
keystroke promptText
43-
key code 36
74+
set finalFront to name of first application process whose frontmost is true
4475
end tell
45-
delay 0.2
76+
if sendOk and finalFront is not appName then
77+
log "wake: WARN — keystroke sent but final frontmost is " & finalFront & " (expected " & appName & ")"
78+
end if
4679
47-
-- Restore focus to the previous app
80+
delay 0.2
81+
-- Restore focus to whatever the user was actually in.
4882
tell application frontApp to activate
4983
end run
5084
APPLESCRIPT

0 commit comments

Comments
 (0)