jackwener/OpenCLI · error · CommandExecutionError

Failed to open ChatGPT chat:

Error message

Failed to open ChatGPT chat: 

What it means

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.

Source

Thrown at clis/chatgpt-app/new.js:58

                    '    end try',
                    '  end tell',
                    'end tell'
                ].map(line => `-e '${line.replace(/'/g, "'\\''")}'`).join(' ');
                execSync(`osascript ${appleScript}`);
                execSync("osascript -e 'delay 0.8'");
                if (!isTemporaryChatVisible()) {
                    throw new CommandExecutionError('Temporary chat did not become visible after selecting the menu item');
                }
            } else {
                execSync("osascript -e 'tell application \"System Events\" to keystroke \"n\" using command down'");
            }
            return [{ Status: 'Success' }];
        }
        catch (err) {
            if (err instanceof CommandExecutionError) {
                throw err;
            }
            throw new CommandExecutionError("Failed to open ChatGPT chat: " + getErrorMessage(err));
        }
    },
});

View on GitHub (pinned to 49907e53dc)

Solutions

  1. Read the underlying message after the prefix to identify the real cause (ENOENT, permission, script error)
  2. Install/launch the ChatGPT Desktop app and grant the calling app Automation permission for ChatGPT and System Events
  3. Run the command from an interactive GUI terminal session, not a headless daemon
Defensive patterns

Strategy: try-catch

Validate before calling

execSync('ls /Applications/ChatGPT.app', { stdio: 'ignore' }); // throws if app missing

Try / catch

try {
  execSync('opencli chatgpt-app new');
} catch (e) {
  const msg = String(e.message);
  if (msg.includes('ENOENT')) console.error('osascript or command not found - run on macOS');
  else if (msg.includes('not allowed assistive')) console.error('Grant Accessibility/Automation permissions');
  else console.error('Failed to open ChatGPT chat:', msg);
}

Prevention

When it happens

Trigger: `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.

Common situations: 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.

Related errors


AI-assisted analysis of jackwener/OpenCLI@49907e53dc (2026-08-29). Data as JSON: /api/errors/b7d82da7eb6b93cb. Report an issue: GitHub.