Python Script execution

You could make it run on boot with crontab.
Lets say your script is located here: /home/pi/script.py

First install crontab
sudo apt-get install cron

If you want to run the scheduled task as root:
sudo crontab -e
otherwise for the osmc user just do:
crontab -e

At the bottom copy paste this (change accordingly with the location and name of your script):
@reboot sudo python /home/pi/script.py

And thats it. Everytime the pi boots, it will run that python script.

For shutdown, you could make a shortcut on your remote that when you press a button, it will execute your shutdown script. Hell, you could do the opposite as well, press a button to switch on the monitor.

I had some problems with this method before, which i explain here:

Somewhere in the middle of the page, i explain how to do it for python.

I am sure there is a simpler way to run scripts on boot/shutdown playing with rc.local, init.d etc, but crontab is much simpler.

If someone can post the ‘experts’ method showing that, it would be awesome.