React to plugging devices with udev rules

The udev system allows to specify rules to react to the plugging of some devices.
This page is adapted from the ArchWiki. Also see writing udev rules

Execute a script when plugging a device

First, create the script to execute. Beware that it should not spawn long-running processes as processing of further events is blocked until the script has finished executing and background tasks spawned by the rule will be killed when the rule processing has finished.
If there is a need for long-running processes use at or similar systems to spawn them detached (e.g. a systemd unit)