{"record":{"id":"b219ff5f9ebd864a","repo":"jackwener/OpenCLI","slug":"failed-to-read-from-chatgpt","errorCode":null,"errorMessage":"Failed to read from ChatGPT: ","messagePattern":"Failed to read from ChatGPT: ","errorType":"exception","errorClass":"CommandExecutionError","httpStatus":null,"severity":"error","filePath":"clis/chatgpt-app/read.js","lineNumber":29,"sourceCode":"    strategy: Strategy.PUBLIC,\n    browser: false,\n    args: [],\n    columns: ['Role', 'Text'],\n    func: async () => {\n        if (process.platform !== 'darwin') {\n            throw new ConfigError('ChatGPT Desktop integration requires macOS (osascript is not available on this platform)');\n        }\n        try {\n            execSync(\"osascript -e 'tell application \\\"ChatGPT\\\" to activate'\");\n            execSync(\"osascript -e 'delay 0.3'\");\n            const messages = getVisibleChatMessages();\n            if (!messages.length) {\n                return [{ Role: 'System', Text: 'No visible chat messages were found in the current ChatGPT window.' }];\n            }\n            return [{ Role: 'Assistant', Text: messages[messages.length - 1] }];\n        }\n        catch (err) {\n            throw new CommandExecutionError(\"Failed to read from ChatGPT: \" + getErrorMessage(err));\n        }\n    },\n});\n","sourceCodeStart":11,"sourceCodeEnd":33,"githubUrl":"https://github.com/jackwener/OpenCLI/blob/49907e53dc3ade5c223ff0c4c2c2785687cec4e6/clis/chatgpt-app/read.js#L11-L33","documentation":"Wrapper error for `chatgpt-app read`: any failure during activation or while collecting visible chat messages via osascript is rethrown as CommandExecutionError 'Failed to read from ChatGPT: ' + underlying message. Unlike new.js it has no special-casing, so all exceptions from the try block flow through here.","triggerScenarios":"`chatgpt-app read` on macOS where execSync/osascript or getVisibleChatMessages() throws: Automation permission denied, app not running, Accessibility tree unavailable, or AppleScript timeout.","commonSituations":"Terminal lacks Accessibility permission; ChatGPT window closed or minimized so no chat UI is exposed; app open with no conversation rendered.","solutions":["Inspect the message after the prefix for the root cause","Grant Accessibility/Automation permissions and ensure a ChatGPT window is open with a conversation visible","Run `chatgpt-app status` first and activate the app before reading"],"exampleFix":"// before\ntry { execSync('opencli chatgpt-app read'); } catch {}\n// after\ntry {\n  execSync(\"osascript -e 'application \\\"ChatGPT\\\" is running'\");\n  execSync('opencli chatgpt-app read');\n} catch (e) { console.error(String(e.stderr || e.message)); }","handlingStrategy":"try-catch","validationCode":"const running = execSync(\"osascript -e 'application \\\"ChatGPT\\\" is running'\").toString().trim() === 'true';\nif (!running) execSync(\"osascript -e 'tell application \\\"ChatGPT\\\" to activate'\");","typeGuard":null,"tryCatchPattern":"try {\n  const out = execSync('opencli chatgpt-app read').toString();\n} catch (e) {\n  console.error('read failed:', String(e.stderr || e.message));\n  if (String(e.message).includes('not allowed')) console.error('Grant Accessibility permission in System Settings');\n}","preventionTips":["Ensure a ChatGPT window with a visible conversation exists before reading","Run `chatgpt-app status` as a precondition check","Capture stderr to see the underlying osascript error behind the wrapper"],"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"}