My school network have a captive portal. Using Google Chrome's "copy as cURL" seems to log me in using curl, but I want to automate this process so it happens as soon as the mac connects to Wi-Fi. How would I achieve that? The curl command is as follows:

curl '' -H 'Connection: keep-alive' -H 'Accept: */*' -H 'Origin:' -H 'X-Requested-With: XMLHttpRequest' -H 'User-Agent: Mozilla/5.0 (Linux; Android 6.0; Nexus 5 Build/MRA58N) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/79.0.3945.88 Mobile Safari/537.36' -H 'DNT: 1' -H 'Content-Type: application/x-www-form-urlencoded; charset=UTF-8' -H 'Referer:' -H 'Accept-Encoding: gzip, deflate' -H 'Accept-Language: zh' -H 'Cookie: ac_login_info=passwork; Sessionid=3566675246-1' --data 'opr=pwdLogin&userName=student&pwd=password&rememberPwd=1' --compressed --insecure

The network name is SCLSCHOOL_G, SCLSCHOOL_F, and SCLSCHOOL_H.


There’s nothing that allows you to kick off a script when you attach to a particular network, so you’ll have to use two tools

  • launchctl You’ll have to start the job based on network availability. Unfortunately, this only checks to see if you’re connected to any network, not a specific one.
  • networksetup that gets the current SSID you’re attached to. The command you will need is

    networksetup -listpreferredwirelessnetworks en1 | grep ${SSID} | cut -f2

Then in a bash script, compare the output of that command and if it matches the SSID you want, run the curl command.

  • Would you mind explaining how to use those two tools? I'm not familiar with using tools in a bash script. – Joy Jin Jan 11 at 3:21
  • And I don't really mind executing the curl command for every network. My home network do not have a device that have the same ip so it doesn't really matter. – Joy Jin Jan 11 at 3:24

You can also put it as a script for all apps and use Script Editor's menu bar button which sits close to Wi-Fi button. ~/Library/Scripts is the folder where the scripts are accessible to all apps.


You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .