Skip to content

Pass connection details to the pre-connect script, and add a post-disconnect script #2498

Closed

Description

@datlechin

Problem

Most of what this issue first asked for has shipped:

  • Pre-Connect Script in the connection's Options tab runs through /bin/bash before connecting, and a non-zero exit aborts the connect (connections/connection-form.mdx:73, from feat: add ~/.pgpass file support and pre-connect script #279).
  • A failure reports the exit code and stderr, Pre-connect script failed (exit N): ... (apple/TablePro/Core/Services/Infrastructure/PreConnectHookRunner.swift:20-27).
  • The script never runs unprompted. An alert shows it and waits for Run Script on every connect, whatever started it (connections/connection-form.mdx:91-93, from fix(connections): ask before any caller runs a pre-connect script #3381), and links, exports and the Team Library do not carry it.
  • A long-running port forward has its own transport, Tunnel Command, which starts on connect and stops on disconnect (connections/tunnel-command.mdx).

Three gaps remain:

  • The script gets TablePro's environment and nothing about the connection. runPreConnectScriptIfNeeded calls PreConnectHookRunner.run(script:) with no environment (apple/TablePro/Core/Database/DatabaseManager+Sessions.swift:289), although the runner accepts one (PreConnectHookRunner.swift:38-52). A script shared by several connections has to hardcode each one's host and user.
  • The timeout is fixed at 10 seconds (PreConnectHookRunner.swift:70-75). A VPN that takes 15 seconds to come up, or an aws sso login that opens a browser, fails every time.
  • Nothing runs after a disconnect, so whatever the script started (a VPN profile, a credential refresh loop) is left running.

Proposed solution

  • Run the pre-connect script with TABLEPRO_CONNECTION_NAME, TABLEPRO_HOST, TABLEPRO_PORT, TABLEPRO_USER and TABLEPRO_DATABASE in its environment. Never the password.
  • A timeout field beside the script, 10 seconds by default, up to 300.
  • A Post-Disconnect Script, run after the session closes, whether by Disconnect, closing the window or quitting. It runs only for a session whose pre-connect script ran, under the same consent rules, and its failure is logged rather than shown as an error.

Done when: a pre-connect script that prints $TABLEPRO_HOST shows the connection's host, a 30 second timeout lets a slow script finish, and a post-disconnect script runs once per approved session.

Alternatives considered

Hardcode the host in each connection's script, wrap the slow step in a background job, and run the cleanup by hand in Terminal.

Platform

macOS

Related database type

N/A / General

Activity

  1. added
    enhancement
    on Aug 26, 2026
  2. changed the title [-]Run a shell command before and after connecting[/-] [+]Pass connection details to the pre-connect script, and add a post-disconnect script[/+] on Oct 19, 2026
  3. added
    platform-macos
    on Oct 19, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    enhancementplatform-macos

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions