How to auto shutdown My Cloud when I shut down my PC?

This link was posted by Ralphael

If you search the site you will see different methods. Since the WD MyCloud single bay does not
have any way for the backup power to indicate that power is lost. You need to use your pc to detect the loss of power and tell the WD MyCloud to shutdown.

PS this method can be used to run any script.