Skip to content

smaddock/xpc_set_event_stream_handler

 
 

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

12 Commits
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

xpc_handler

A demonstration of using launchd LaunchEvents to trigger LaunchDaemons on-demand (as opposed to cron-like triggering) by taking advantage of Apple's XPC framework. This allows, for example, commands to be run when the network configuration or power state of a Mac changes.

Feel free to use this example per the terms of the included license, although you'll probably want to remove the smaddock references from any production use. ;)

This is a port of @snosrap's Objective-C XPC event handler to a Javascript for Automation (JXA) handler. Many thanks to @PicoMitchell for the JXA help!

Notes

Usage

To execute this example as-is:

  1. Install the files
    • munkipkg method:
      1. Install munkipkg
      2. Clone this repository locally
      3. Run munkipkg on the repo local root directory
      4. Run the installer built by munkipkg
    • Manual method:
      1. Copy the files from the payload directory of this repo to their corresponding location in your filesystem
      2. Change the owner of all the copied files to root
      3. Run sudo launchctl bootstrap system /Library/LaunchDaemons/com.github.smaddock.xpc_handler.plist
  2. Test the LaunchEvents
    • Turn your WiFi off and on a couple times
    • Sleep and wake your Mac a couple times
  3. Inspect /private/var/log/smaddock.log to see the logged events

About

No description, website, or topics provided.

Resources

License

Stars

Watchers

Forks

Languages

  • Shell 57.9%
  • JavaScript 42.1%