Is there any way i can program an onclick button to do two actions.
1. Quit kodi
2. wait 1 or 2 seconds
3. launch a windows .exe
I need to quit kodi before i launch a windows exe.
thanks
I would put the logic in a batch file and call that from the onclick
So, you want an application (Kodi) that has already totally stopped running, still execute another Windows application, after 2-3 seconds of being already stopped. It sounds a bit like an act from beyond the grave to me. Pretty unlikely.
(2017-09-22, 15:33)BigNoid Wrote: [ -> ]I would put the logic in a batch file and call that from the onclick
That is exactly what i was going to do. however i do not know how to quit Kodi from a batch file. I do not want to use the windows kill command as it does not save the changes.
Thanks
I have something like this in a restart script.
See below for a working example.
Stick test.py wherever and run from a favourite / key / skin shortcut.
Stick test.bat in userdata/batch folder
Edit test.bat to the path of whatever .exe you want to start.
test.py:
Code:
#!/usr/bin/python
# -*- coding: utf-8 -*-
import xbmc
import os
import subprocess
from subprocess import Popen
print 'running test.py'
USERDATA = xbmc.translatePath('special://masterprofile')
batchfolder = os.path.join(USERDATA, 'batch')
batchfile = os.path.join(batchfolder, 'test.bat')
assert os.path.isdir(batchfolder)
os.chdir(batchfolder)
subprocess.Popen('test.bat', close_fds=True, shell=True)
xbmc.executebuiltin('Notification(Stopping, kodi)')
xbmc.sleep(1000)
xbmc.executebuiltin('Quit')
exit()
test.bat:
Code:
@ECHO OFF
rem temp add
Timeout /T 2 /Nobreak
:LOOP
tasklist | find /i "kodi" >nul 2>&1
IF ERRORLEVEL 1 (
GOTO CONTINUE
) ELSE (
ECHO Kodi is still running
Timeout /T 2 /Nobreak
GOTO LOOP
)
:CONTINUE
rem Timeout /T 2 /Nobreak
START "" "C:\Program Files\WinSCP\WinSCP.exe"
There may well be an easier way - that's what I ended up with.
edit: just realised we're in skinning, but the principle is the same.
Troggy, thank you very much i was looking for something like this for a long while.
worked like a charm. Running it using <onclick>RunScript(special://userdata/test.py)</onclick>
Created two different version:
1. quits and start kodi (could not get the builtin RestartApp function to work in windows)
2. quits and start explorer
Do you know off a way to first quit and then put computer to sleep. I could use your script and put the sleep function in batch. but wanted to know if there is anything better using python.
I've never looked at sleep - tbh I use libreelec for kodi 90% of the time - I'd probably do it via the batch file but that just means it's an obvious route, not that it's necessarily the best.
Glad it's done the job, anyway, and thanks for feeding back.
Hi there
I've the put this topic back to the top as I need almost the same function.
I'd like to create a shortcut in my menu, and then I want to start the script (for quitting Kodi and restart/shutdown).
I copied test.py and test.bat into userdata\batch and created a shortcut in my favourites:
<favourite name="TestScript">RunScript(special://profile/batch/test.py)</favourite>
But if I start it, nothing happens.
Is there something more required?
Thanks for your help :-)
edit:
OK, got it :-)
I put the python script into an addon, which starts the .bat file
Works great :-)
(2017-09-22, 16:28)trogggy Wrote: [ -> ]I have something like this in a restart script.
See below for a working example.
Stick test.py wherever and run from a favourite / key / skin shortcut.
Stick test.bat in userdata/batch folder
Edit test.bat to the path of whatever .exe you want to start.
test.py:
Code:
#!/usr/bin/python
# -*- coding: utf-8 -*-
import xbmc
import os
import subprocess
from subprocess import Popen
print 'running test.py'
USERDATA = xbmc.translatePath('special://masterprofile')
batchfolder = os.path.join(USERDATA, 'batch')
batchfile = os.path.join(batchfolder, 'test.bat')
assert os.path.isdir(batchfolder)
os.chdir(batchfolder)
subprocess.Popen('test.bat', close_fds=True, shell=True)
xbmc.executebuiltin('Notification(Stopping, kodi)')
xbmc.sleep(1000)
xbmc.executebuiltin('Quit')
exit()
test.bat:
Code:
@ECHO OFF
rem temp add
Timeout /T 2 /Nobreak
:LOOP
tasklist | find /i "kodi" >nul 2>&1
IF ERRORLEVEL 1 (
GOTO CONTINUE
) ELSE (
ECHO Kodi is still running
Timeout /T 2 /Nobreak
GOTO LOOP
)
:CONTINUE
rem Timeout /T 2 /Nobreak
START "" "C:\Program Files\WinSCP\WinSCP.exe"
There may well be an easier way - that's what I ended up with.
edit: just realised we're in skinning, but the principle is the same.
I know this is a mega old thread... but I have been looking everywhere for something like this - however I'm new to all this and don't quite understand how to install this stuff, is there anyone that could just explain how I would go about adding this script please
(2020-04-18, 23:36)EuqinuX Wrote: [ -> ] (2017-09-22, 16:28)trogggy Wrote: [ -> ]I have something like this in a restart script.
See below for a working example.
Stick test.py wherever and run from a favourite / key / skin shortcut.
Stick test.bat in userdata/batch folder
Edit test.bat to the path of whatever .exe you want to start.
test.py:
Code:
#!/usr/bin/python
# -*- coding: utf-8 -*-
import xbmc
import os
import subprocess
from subprocess import Popen
print 'running test.py'
USERDATA = xbmc.translatePath('special://masterprofile')
batchfolder = os.path.join(USERDATA, 'batch')
batchfile = os.path.join(batchfolder, 'test.bat')
assert os.path.isdir(batchfolder)
os.chdir(batchfolder)
subprocess.Popen('test.bat', close_fds=True, shell=True)
xbmc.executebuiltin('Notification(Stopping, kodi)')
xbmc.sleep(1000)
xbmc.executebuiltin('Quit')
exit()
test.bat:
Code:
@ECHO OFF
rem temp add
Timeout /T 2 /Nobreak
:LOOP
tasklist | find /i "kodi" >nul 2>&1
IF ERRORLEVEL 1 (
GOTO CONTINUE
) ELSE (
ECHO Kodi is still running
Timeout /T 2 /Nobreak
GOTO LOOP
)
:CONTINUE
rem Timeout /T 2 /Nobreak
START "" "C:\Program Files\WinSCP\WinSCP.exe"
There may well be an easier way - that's what I ended up with.
edit: just realised we're in skinning, but the principle is the same.
I know this is a mega old thread... but I have been looking everywhere for something like this - however I'm new to all this and don't quite understand how to install this stuff, is there anyone that could just explain how I would go about adding this script please
Hi Troggy, so I got your script working, however I'm having a weird problem with the batch file - on my main PC everything works great, I can launch another app and then I also have it reopen Kodi once said app has closed... however when I run it on my media PC (which is quite old and slow) sometimes it works but then sometimes it will launch the app or launch Kodi with the focus off the app. E.g. Kodi will start back up again but the taskbar is still visible. It's kind of still in focus... I can still control it, but the taskbar is in the way (or if I have other programs open sometimes they will be in the way)
Any ideas?