mplugd is a daemon that listens on events (e.g. xrandr or pulseaudio) and executes user-defined actions on certain events. In contrast to other approaches, it listens to events by registering callback handlers instead of polling and parsing tool output. Event processing is done through a threaded producer/consumer architecture that can be extended by plugins to insert new event types. Actions can be defined using INI-like rule files or simple scripts.
A common use-case is automatic configuration of plugged-in devices like HDMI or DisplayPort displays including switch of audio output using pulseaudio.
Source code: mplugd on GitHub