'kodi-send' in Script doesn't work when executed from Power menu

  • Hi there.

    Got another issue... :)

    I have a simple bash script that works when added as a menu item to a regular submenu, e.g. Settings. The script is executed as 'custom command' with System.Exec(). If I instead create the menu item calling the script in the "Power" menu, it does not work.

    This is the script:

    Bash
    #!/bin/bash
    
    # Check if anything gets downloaded and prevent shutdown
    # Set this script in Kodi's Power menu with "System.Exec()"
    
    if [ -e /tmp/downloadflag ] ; then
            kodi-send --action="Notification(Download in progress,Shutdown aborted!,20000)"
    else
            kodi-send --action=Powerdown
    fi

    If I insert a touch ~/EXECUTED before the kodi-send line, that file gets created alright, so the script does get called. It seems like it's really the "kodi-send" that doesn't work.

    Any ideas why that may be?

    Thanks!

  • You misunderstood. There's actual weirdness happening...

    There's no shutdown progress going on. I just replaced the "Shutdown" item of the Power menu (that normally calls the kodi build-in "Powerdown()") with a System.Exec() call of the above script. No shutdown is initiated.

    My script just determines if there are downloads queued (my sytem generates a file /tmp/downloadflag when that's the case). If there are, kodi is made to show a notification, otherwise the regular kodi command to Powerdown() is triggered.

    If I execute this script when logged in via SSH, it works as expected. If I System.Exec() that script from a normal menu in Kodi, it works, too. Only if I System.Exec() from the "Power" menu it does not work.

    Weird.

  • That's already part of my theory. I believe that all entries inside power menu will stop the kodi process.

    Use other commands, like shutdown, poweroff or reboot.

    PS: If you wish to interrupt the shutdown procedure, because a download is still active, you have to restart the kodi process.

  • I use several script calls in the Power Menu, and they often include kodi-send command, and everything works exactly as expected. There is no reason why something in the Power Menu should work differently than in other menus. The Power Menu is just like any other menu, the only thing that makes it "Power" is that it uses Kodi commands to control the status of Kodi and power status of the system.

  • I use several script calls in the Power Menu, and they often include kodi-send command, and everything works exactly as expected. There is no reason why something in the Power Menu should work differently than in other menus. The Power Menu is just like any other menu, the only thing that makes it "Power" is that it uses Kodi commands to control the status of Kodi and power status of the system.

    Thanks for this! In that case it would help to see a log.

    Please provide a full debug log.

    How to post a log (wiki)

    1. Enable debugging in Settings>System Settings>Logging
    2. Restart Kodi
    3. Replicate the problem
    4. Generate a log URL (do not post/upload logs to the forum)

    use "Settings > LibreELEC > System > Paste system logs" or run "pastekodi" over SSH, then post the URL link
  • OK, here's the log: http://0x0.st/opx_.log

    I boot up, call the Power menu with a keypress on my remote control and select "Shutdown" from the menu. This does System.Exec() the above script.

    That said, it appears to me that Da Flex is right. From the log it looks like after invoking "Shutdown", kodi is kinda "un-pausing", doing HW inits etc.

    Also, with a trick I can make my scripts work: I just sleep for 2 seconds before sending the kodi-send commands, which is enough for Kodi to be attentive again and react to those commands. For that to work, the script has to immediately return and do the sleeping in the background. For that I moved everything into a function.

    That's the working script:

    Though it's working, I'd be willing to experiement further, if you guys come up with things to try...

    Thanks so far!