Run commands when switching theme

When switching a Plasma theme I also would like to change themes for Plymouth, Grub and Lightdm.

I know how to run a command with nodejs:

const execSync = require('child_process').execSync;
var output = execSync('/usr/sbin/plymouth-set-default-theme -R my-plymouth-theme', { encoding: 'utf-8' });
console.log('Change Plymouth theme:\n', output);

And I’d like to include it in a js script like:

Is this possible?