Restarting kodi on keyboard input


Im trying to close kodi once it is idle for an amount of time but then I want to restart it again on keyboard input. Ive made a version of a bash script to do this based on these two links

My tv always is listed on tvservice -n (Its a rubbish tv) so I cant use on tv on/off to stop and start kodi as long as its been on since my pi was started

I dont want to have to login through ssh etc if I can avoid it to restart kodi (im trying to make it simple for everyone to use)

This is what ive got so far:

if pidof kodi.bin; then
    IsIdle=$(curl -s -u osmc:osmc -X POST -H 'Content-type: application/json' -d '{"jsonrpc": "2.0", "method": "XBMC.GetInfoBooleans", "params": { "booleans": ["System.IdleTime(600) "] }, "id": 1}' http://localhost:80/jsonrpc)

    if [[ "$IsIdle" =~ true || "$IsIdle" =~ error ]]; then
    # system idle or could not requested
         sudo systemctl stop mediacenter
         tvservice -o
   # system not idle 

    #some method of waiting for keyboard input
    read junk 
    if [[ "$junk" =~ "restart" ]] 
        tvservice -e"CEA 19"
        sudo systemctl start mediacenter

sleep 60


The first part works fine but I don’t really have a clue how to restart kodi again as there is no bash prompt open when you close kodi like this. Without turning off the hdmi, pressing esc doesnt seem to open the bash prompt.

I also dont know whether you could get any input into crontab etc to run the script in the first place, ive never used it before. Any ideas?