Skip to content

v2 — Automatic interface detection

Latest

Choose a tag to compare

@adamshand adamshand released this 18 Aug 09:08

Highlights

  • Zero-configuration setup: network interfaces are now discovered automatically; editing ETHERNET_REGEX or WIFI_REGEX is no longer required.
  • Multiple wired adapters: Wi-Fi is disabled when any detected Ethernet, dock, or Thunderbolt en interface is active.
  • Correct Wi-Fi power detection: the script checks radio power directly instead of confusing an unassociated Wi-Fi connection with a powered-off radio.
  • Respect for manual Wi-Fi choices: Wi-Fi is restored only when this script previously disabled it.
  • Seamless upgrades: legacy launchd services and their Wi-Fi state are detected and migrated automatically.

UX and reliability

  • Added wifi-toggle.sh status to show launchd state, the installed script and service version, detected interfaces, Wi-Fi power, wired link state, and pending restoration.
  • Made wifi-toggle.sh on safely update and reload an existing service; off is also idempotent and restores Wi-Fi when appropriate.
  • Added clear root-user detection and corrected command help and exit statuses.
  • Propagated interface, Wi-Fi power, and launchctl failures instead of reporting false success.
  • Notifications are now sent only after successful Wi-Fi changes.
  • launchd plists are generated privately, XML-escaped, validated with plutil, and installed atomically.
  • The script is now executable in the repository.
  • Expanded installation, upgrade, usage, and troubleshooting documentation.

Upgrading from v1

  1. Copy the new wifi-toggle.sh over the old script and ensure it remains executable:

    chmod 755 /path/to/wifi-toggle.sh
  2. Run the new script's on command to validate, version, and reload the installed service:

    /path/to/wifi-toggle.sh on

You do not need to run the old version's off command first. If the script is replaced at the same path, launchd will use the new code on its next invocation; running on is still recommended.

Full changelog: v1...v2