--- /Users/osi/Desktop/tkMacOSXInit.c 2023-08-08 13:24:24.000000000 -0400 +++ tk/macosx/tkMacOSXInit.c 2023-08-08 13:23:47.000000000 -0400 @@ -467,50 +467,36 @@ Tcl_DoOneEvent(TCL_WINDOW_EVENTS | TCL_DONT_WAIT); /* - * Decide whether to open a console window. If the TK_CONSOLE - * environment variable is not defined we only show the console if - * stdin is not a tty and there is no startup script. + * If we don't have a TTY and stdin is a special character file of + * length 0, (e.g. /dev/null, which is what Finder sets when double + * clicking Wish) then use the Tk based console interpreter. */ - if (getenv("TK_CONSOLE")) { - shouldOpenConsole = YES; - } else if (stdinIsNullish && Tcl_GetStartupScript(NULL) == NULL) { - const char *intvar = Tcl_GetVar2(interp, "tcl_interactive", - NULL, TCL_GLOBAL_ONLY); - if (intvar == NULL) { - Tcl_SetVar2(interp, "tcl_interactive", NULL, "1", - TCL_GLOBAL_ONLY); - } - -#if defined(USE_CUSTOM_EXIT_PROC) - doCleanupFromExit = YES; -#endif - - shouldOpenConsole = YES; - } - if (shouldOpenConsole) { + if (getenv("TK_CONSOLE") || + (!isatty(0) && (fstat(0, &st) || + (S_ISCHR(st.st_mode) && st.st_blocks == 0)))) { Tk_InitConsoleChannels(interp); Tcl_RegisterChannel(interp, Tcl_GetStdChannel(TCL_STDIN)); Tcl_RegisterChannel(interp, Tcl_GetStdChannel(TCL_STDOUT)); Tcl_RegisterChannel(interp, Tcl_GetStdChannel(TCL_STDERR)); - if (Tk_CreateConsoleWindow(interp) == TCL_ERROR) { - return TCL_ERROR; - } - } else if (stdinIsNullish) { /* - * When launched as a macOS application with no console, - * redirect stderr and stdout to /dev/null. This avoids waiting - * forever for those files to become writable if the underlying - * Tcl program tries to write to them with a puts command. + * Only show the console if we don't have a startup script and + * tcl_interactive hasn't been set already. */ - FILE *null = fopen("/dev/null", "w"); - dup2(fileno(null), STDOUT_FILENO); - dup2(fileno(null), STDERR_FILENO); -#if defined(USE_CUSTOM_EXIT_PROC) - doCleanupFromExit = YES; -#endif + if (Tcl_GetStartupScript(NULL) == NULL) { + const char *intvar = Tcl_GetVar2(interp, + "tcl_interactive", NULL, TCL_GLOBAL_ONLY); + + if (intvar == NULL) { + Tcl_SetVar2(interp, "tcl_interactive", NULL, "1", + TCL_GLOBAL_ONLY); + } + } + if (Tk_CreateConsoleWindow(interp) == TCL_ERROR) { + return TCL_ERROR; + } } /*