Is it possible to have a program starting automatically when I connect to a specific router, and having it stop when I disconnect from this router?

Basically I want a program to run while I'm at work (flexible hours, so I can't just have some sort of timer function) but not when I'm at home - or somewhere else.

I'm running: Macbook air OS X Version 10.9.4

  • What kind of program Yuo would like to launch/terminate? I can write You a daemon which will execute bash script and pass "SSID" on connect and also "SSID" of disconnected network. Jul 18, 2014 at 11:05
  • Nevermind, i see that George found better solutions :) Jul 18, 2014 at 11:11
  • 1
    @Mateusz 3rd-party software isn't always a better solution, just an alternative!
    – grg
    Jul 18, 2014 at 11:12
  • 1
    @MateuszSzlosek, I'm also curious what your solution would've been. For my purpose, I'd prefer something less than another application, as I'd be using your solution to hook up my application.
    – rsaxvc
    Dec 28, 2014 at 17:18
  • 1
    @rsaxvc I've posted Github link with my quick implementation. A lot can be changed but You'll get the basics :) Dec 29, 2014 at 15:10

4 Answers 4


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.

  • 1
  • @Seamus I’ve added a link to a maintained fork which includes Mojave support.
    – grg
    Apr 11, 2019 at 19:56
  • Thanks, but what does "unofficial fork" mean? Do you know?
    – Seamus
    Apr 11, 2019 at 20:03
  • @Seamus I use the term to describe the manner in which the open source project was continued. ControlPlaneX is a ‘fork’ of ControlPlane, meaning it continues using the same source code as the original and building on top of it, which is possible because the original project was open source. If the original author of the project chooses a fork to encourage people to contribute to, this becomes an official fork, however it does not appear that the original author has done so with any fork, therefore all forks are unofficial, hence ‘unofficial fork’. This one appears to be the most popular fork.
    – grg
    Apr 11, 2019 at 20:31
  • Interesting situation then... the original owner requested help, and instead someone forked & went their own way. All's fair in love & open source I suppose :)
    – Seamus
    Apr 11, 2019 at 21:52

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.

  • 2
    Thanks for the inspiration Mateusz, I've created an app similar to yours to execute my VPN connection scripts, on Github including a compiled app binary for those wo might need it: github.com/p2/WifiWatch
    – Pascal
    Nov 25, 2016 at 14:46
  • Does this work in Catalina?
    – FlorianL
    Sep 23, 2020 at 18:32

You can use Sidekick which lets you perform 'actions' when changing location. The location is reported using the specific Wi-Fi, which means you can do things when the Wi-Fi changes.

Sidekick is an application that automatically updates your laptop settings based on where you are. Just install the app, configure the places that you frequent, (home, work, a coffee shop, etc.) and never fuss with your settings again!

  • 3
    Sidekick is currently $29.00 Dec 29, 2014 at 15:22

wifi-location-changer is a project on GitHub which runs the shell script locationchanger every time the Wifi SSID changes. locationchanger sets the variable LOCATION and runs scselect "$LOCATION", you can replace that with your own action.

You must log in to answer this question.

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