Run program if connected to specific wifi?
Solution 1:
You can use ControlPlane where you can set up rules to carry out tasks such as opening apps based on various criteria which includes connecting to Wi-Fi.
ControlPlane supports multiple contexts where a context is defined as a location or activity you are performing. Using evidence sources you can create a set of rules that tell ControlPlane what context to apply to your environment. When ControlPlane enters or leaves a context a set of Actions are performed.
ControlPlaneX, an unofficial fork of the open source project, has kept the project working to Mojave.
Solution 2:
I've created sample daemon app for this purpose. You can find it on Github.
To make it run:
- Compile it using Xcode.
- Move
Network Listener.app
to/Applications
dir. - Move
.networkConnected
and.networkDisconnected
to Your$HOME
dir. - Move
Network-Listener.plist
to~/Library/LaunchAgents
. - Make
.networkConnected
and.networkDisconnected
executable.
It will automatically run when You log in to Your account. If You want to test it run this in Terminal:
launchctl load -S Aqua -w ~/Library/LaunchAgents/Network-Listener.plist
Scripts receive SSID name as arguments.
Feel free to change it for Your needs. In case of any problems let me know.
Everything was created to show the possibilities, a lot of things can be improved.