{"record":{"id":"b7d82da7eb6b93cb","repo":"jackwener/OpenCLI","slug":"failed-to-open-chatgpt-chat","errorCode":null,"errorMessage":"Failed to open ChatGPT chat: ","messagePattern":"Failed to open ChatGPT chat: ","errorType":"exception","errorClass":"CommandExecutionError","httpStatus":null,"severity":"error","filePath":"clis/chatgpt-app/new.js","lineNumber":58,"sourceCode":"                    '    end try',\n                    '  end tell',\n                    'end tell'\n                ].map(line => `-e '${line.replace(/'/g, \"'\\\\''\")}'`).join(' ');\n                execSync(`osascript ${appleScript}`);\n                execSync(\"osascript -e 'delay 0.8'\");\n                if (!isTemporaryChatVisible()) {\n                    throw new CommandExecutionError('Temporary chat did not become visible after selecting the menu item');\n                }\n            } else {\n                execSync(\"osascript -e 'tell application \\\"System Events\\\" to keystroke \\\"n\\\" using command down'\");\n            }\n            return [{ Status: 'Success' }];\n        }\n        catch (err) {\n            if (err instanceof CommandExecutionError) {\n                throw err;\n            }\n            throw new CommandExecutionError(\"Failed to open ChatGPT chat: \" + getErrorMessage(err));\n        }\n    },\n});\n","sourceCodeStart":40,"sourceCodeEnd":62,"githubUrl":"https://github.com/jackwener/OpenCLI/blob/49907e53dc3ade5c223ff0c4c2c2785687cec4e6/clis/chatgpt-app/new.js#L40-L62","documentation":"Generic wrapper in `chatgpt-app new`: any error thrown while activating the app or creating a chat (that is not already a CommandExecutionError) is rethrown as a CommandExecutionError prefixed 'Failed to open ChatGPT chat: ' plus the underlying message. It groups osascript/exec failures into one user-facing error.","triggerScenarios":"`chatgpt-app new` where execSync('osascript ...') fails: osascript not found, ChatGPT app not installed/renamed, AppleScript Automation permission denied, System Events keystroke rejected, or spawn ENOENT/EACCES errors.","commonSituations":"First-run macOS permission prompts dismissed; ChatGPT Desktop app not installed; PATH lacking /usr/bin in exec environments; running under a daemon without GUI session access.","solutions":["Read the underlying message after the prefix to identify the real cause (ENOENT, permission, script error)","Install/launch the ChatGPT Desktop app and grant the calling app Automation permission for ChatGPT and System Events","Run the command from an interactive GUI terminal session, not a headless daemon"],"exampleFix":null,"handlingStrategy":"try-catch","validationCode":"execSync('ls /Applications/ChatGPT.app', { stdio: 'ignore' }); // throws if app missing","typeGuard":null,"tryCatchPattern":"try {\n  execSync('opencli chatgpt-app new');\n} catch (e) {\n  const msg = String(e.message);\n  if (msg.includes('ENOENT')) console.error('osascript or command not found - run on macOS');\n  else if (msg.includes('not allowed assistive')) console.error('Grant Accessibility/Automation permissions');\n  else console.error('Failed to open ChatGPT chat:', msg);\n}","preventionTips":["Run from an interactive macOS GUI session, not a headless daemon","Install the ChatGPT Desktop app and complete first-run permission prompts","Log stderr (not just the wrapper prefix) to see root causes"],"tags":["applescript","desktop-app","error-wrapper"],"backgroundTag":"command-execution-failed","analyzedSha":"49907e53dc3ade5c223ff0c4c2c2785687cec4e6","analyzedAt":"2026-08-29T08:14:47.543Z","schemaVersion":2},"datasetVersion":"2026-08-29T12:17:43.993Z"}