https://github.com/jeff2ma/launchd-with-networkchange
A tool with shell script and launchd to trigger actions whenever a Mac's network information is changed.
https://github.com/jeff2ma/launchd-with-networkchange
launchd macos network trigger-actions
Last synced: 2 months ago
JSON representation
A tool with shell script and launchd to trigger actions whenever a Mac's network information is changed.
- Host: GitHub
- URL: https://github.com/jeff2ma/launchd-with-networkchange
- Owner: Jeff2Ma
- License: mit
- Created: 2016-11-24T11:27:57.000Z (over 8 years ago)
- Default Branch: master
- Last Pushed: 2021-10-27T04:33:24.000Z (over 3 years ago)
- Last Synced: 2025-03-26T10:21:31.592Z (3 months ago)
- Topics: launchd, macos, network, trigger-actions
- Language: Python
- Homepage:
- Size: 151 KB
- Stars: 128
- Watchers: 5
- Forks: 20
- Open Issues: 1
-
Metadata Files:
- Readme: readme.md
- License: LICENSE
Awesome Lists containing this project
README
# launchd with networkchange
A tool with shell script and launchd to trigger actions whenever a Mac's network information is changed.
[[简体中文版使用说明] 请点击这里](https://github.com/Jeff2Ma/launchd-with-networkchange/blob/master/readme.zh.md)
## Introduction
This repo is an easy way to deal with contexts like:
> At workplace, your Mac Device has to make some settings such as change proxy address, set specical pac file, open some apps and so on. While at home your have change it again to others.
With the help of [launchd](https://developer.apple.com/library/content/documentation/MacOSX/Conceptual/BPSystemStartup/Chapters/CreatingLaunchdJobs.html), those operations can be automated. And that's what this repo do! It is fast, easy and safe.
## Features
- Easy to install and uninstall.
- Password of your system account will be saved in keychain safely.
- Add example so that your can easily change the code according to your conditions.
## How to start
```bash
$ git clone https://github.com/Jeff2Ma/launchd-with-networkchange$ cd launchd-with-networkchange
$ python install.py
```
Then input the info when is asked.
After that, please edit the code in `example.sh ` according to your conditions.
When your Mac's network change, a notification will show when it run shell script with success.

## Notices
1) When the first run of the script, system will ask you like:

Remember to choose `Always Allow`.
2)you can make a `example.sh` copy one and rename it to `dynamic.sh`, it will be run instead of `example.sh`[see how it work](https://github.com/Jeff2Ma/launchd-with-networkchange/blob/master/_demo/_run.applescript#L23-L29).
3) If you want to uninstall it, you can run `python install.py uninstall`.
4) Check `/var/log/system.log` if you are having issues with `plist`.
## Contributing
Thanks to this [Repo](https://github.com/tjluoma/onnetworkchange) and this [Alfred Workflow](https://github.com/Jeff2Ma/AlfredWorkflow-DuoTai-Helper) to provide inspiration for me.
[Issues](https://github.com/Jeff2Ma/launchd-with-networkchange/issues) and [Pull requests](https://github.com/Jeff2Ma/launchd-with-networkchange/pulls) are warm welcome.