Parallels VM: Is there a way to run a script on the host when launching a VM? My Parallels VM is configured to use some network services on the host mac via the virtual network, but as the virtual network is not up when the mac host's services are started at boot they aren't listening on the virtual interface and the VM can't connect to them. After starting the VM I have to remember to manually restart those services on the mac host so that they are listening on the virtual network. It's annoying when I forget to do so...
I'd like to automate this process if possible. Is there any way to configure Parallels to run a shell script on the host after a VM is started and the virtual network is up? (Suggestions for how to run a startup script on the guest VM are not germane.)
Absent somebody pointing out a way to do this within Parallels itself, here's a solution using only native utilities - thanks @user3439894 for suggesting a Launch Agent!

Create a /usr/local/bin/parallels_vm_starting shell script and chmod 755 it to make it executable:

#!/bin/bash

(
    echo &quot;----------&quot;
    date

    if /usr/bin/tty -s
    then
        echo &quot;interactive&quot;
    else
        # sleep for a bit to give things a chance to settle
        echo &quot;background - let things settle&quot;
        sleep 15
        date
    fi

    # Actions to perform when hosted VM starts up

    /usr/local/Homebrew/bin/brew services restart redis

    # etc. as needed

    date

) 2&gt;&amp;1 | tee -a /tmp/vm-startup.log


Create a Launch Agent file ~/Library/LaunchAgents/parallels_vm_startup.plist with this content:

&lt;?xml version=&quot;1.0&quot; encoding=&quot;UTF-8&quot;?&gt;
&lt;!DOCTYPE plist PUBLIC &quot;-//Apple Computer//DTD PLIST 1.0//EN&quot; &quot;http://www.apple.com/DTDs/PropertyList-1.0.dtd&quot;&gt;
&lt;plist version=&quot;1.0&quot;&gt;
&lt;dict&gt;
    &lt;key&gt;Label&lt;/key&gt;
        &lt;string&gt;parallels_vm_startup&lt;/string&gt;
    &lt;key&gt;ProgramArguments&lt;/key&gt;
        &lt;array&gt;
            &lt;string&gt;/usr/local/bin/parallels_vm_starting&lt;/string&gt;
        &lt;/array&gt;
    &lt;key&gt;WatchPaths&lt;/key&gt;
        &lt;array&gt;
            &lt;string&gt;/Library/Preferences/Parallels/parallels_dhcp_leases&lt;/string&gt;
        &lt;/array&gt;
    &lt;key&gt;StandardOutPath&lt;/key&gt;
        &lt;string&gt;/dev/null&lt;/string&gt;
&lt;/dict&gt;
&lt;/plist&gt;

This will monitor the file /Library/Preferences/Parallels/parallels_dhcp_leases, which Parallels modifies when the VM starts (assuming the VM has networking enabled), and will execute the shell script when that happens.
Note: the DHCP leases file is regularly updated while the VM is up. If you only want to react to a VM being launched or shut down, monitor the file /Library/Preferences/Parallels/vmdirectorylist.desktop.xml instead.

Activate the Agent: launchctl load ~/Library/LaunchAgents/parallels_vm_startup.plist