This script will automatically log-in to my workplace's captive portal every time I connect to the wi-fi. It's currently only designed to work with my workplace's wi-fi, but it is easily adaptable. Simply change the SSID on line 43 from "8451-EiR" to whatever your network's SSID is. Then change the curl command on line 44 to be a curl command that logs into your workplace's wi-fi. You can find out this command using your browser's inspector tools to examine the captive portal's login form, or using a proxy tool like Charles Proxy, mitmproxy, or Fiddler.
This script is limited to macOS (aka Mac OS X), and that's not very easily changed; sorry.
If you want to distribute this to non-developers, I recommend bundling it into an app using appify; here's a nice tutorial (it's super easy).
Once you choose to install and enter your username and password, the installer first creates a bash script at ~/Library/Application Support/8451login.sh
. This script doesn't do much; it simply checks that the current SSID is "8451-EiR" and, if it is, uses curl to POST the username and password to the login page. The installer then makes the bash script executable.
Next, the installer creates an XML file at ~/Library/LaunchAgents/local.8451login.plist
. This is a config file for launchd, and it basically says that, whenever any of the computer's network config files get changed (which happens whenever connecting/disconnecting/etc from a network), the ~/Library/Application Support/8451login.sh
script will get run.
Lastly, the installer tells launchd to load the new plist file, and then runs the script once to make sure it takes effect right away. When the computer reboots in the future, launchd will automatically load the plist file.