fix: use AppleScript-safe escaping and reduce spawnSync timeout

- Replace JSON.stringify with curly quote substitution for AppleScript
  compatibility (AppleScript does not support \" backslash escapes)
- Reduce spawnSync timeout from 5000ms to 3000ms to leave headroom
  within the 5s hook deadline
This commit is contained in:
Jonghyeok Park
2026-03-24 10:36:00 +09:00
parent 445ae5099d
commit d3699f9010

View File

@@ -40,11 +40,14 @@ function extractSummary(message) {
/**
* Send a macOS notification via osascript.
* Uses spawnSync with an argument array to avoid shell injection.
* AppleScript strings do not support backslash escapes, so we replace
* double quotes with curly quotes and strip backslashes before embedding.
*/
function notifyMacOS(title, body) {
const script = `display notification ${JSON.stringify(body)} with title ${JSON.stringify(title)}`;
spawnSync('osascript', ['-e', script], { stdio: 'ignore', timeout: 5000 });
const safeBody = body.replace(/\\/g, '').replace(/"/g, '\u201C');
const safeTitle = title.replace(/\\/g, '').replace(/"/g, '\u201C');
const script = `display notification "${safeBody}" with title "${safeTitle}"`;
spawnSync('osascript', ['-e', script], { stdio: 'ignore', timeout: 3000 });
}
// TODO: future platform support