Executing a script from Kodi's file manager (solved)
#1
I have a Python script that turns on/off some lights via a Tellstick Znet.
I just got it to work using Putty and SSH.
I can execute it on my Raspberry from my laptop using Putty and it works fine.

But it doesn't work when I try to run it from Kodi's File manager.

I can run other Python scripts from the File manager though.

I'm guessing the "import os" has something to do with it.
I'm very very new to Python Smile

This doesn't work:
Code:
#!/usr/bin/env python
import os
os.system("python TDTools_beta.py --off 33")


This works:
Code:
#!/usr/bin/env python
import subprocess
proc = subprocess.Popen(["curl", "https://maker.ifttt.com/trigger/Turn_off/with/key/enen92"])
Reply
#2
Update...
Read some more on Python and using os.system is not advisable apparently Smile

Got this to work via SSH (Putty) but it still doesn't work through the File manager in KodiHuh

Code:
#!/usr/bin/env python
import subprocess
proc = subprocess.Popen("python TDTools_beta.py '--off' '33'", shell=True)
Reply
#3
Note you wont be able to execute the script from within the file manager. Best chance is with a context menu addon ( kodi.wiki/view/Context_Item_Add-ons ) or build a script/ plugin dedicated to it
Reply
#4
Also please change your key/hide it from your message otherwise anyone can play with your lights
Reply
#5
key obfuscated.
Do not PM or e-mail Team-Kodi members directly asking for support.
Always read the Forum rules, Kodi online-manual, FAQ, Help and Search the forum before posting.
Reply
#6
(2017-01-25, 03:39)ronie Wrote: key obfuscated.
Oups, didn't think about that one. Thanks!


Why won't I be able to execute the script from the File manager?

I mean, this very alike script works?

Code:
#!/usr/bin/env python
import subprocess
proc = subprocess.Popen(["curl", "https://maker.ifttt.com/trigger/Turn_off/with/key/enen92"])
Reply
#7
You cannot execute scripts from within the filemanager, it is made to manipulate xbmcvfs.
However, kodi is really extensible when it comes to plugins. Making a plugin to do a simple webrequest is really easy. Here you have a plugin I made in 5 minutes to solve your issue (it creates 2 listitems - one to turn the lights on, other to turn the lights off). It grabs the response HTTP status code and presents a notification if the status code is 200 and an error message otherwise:

https://wetransfer.com/downloads/06c106a...406/5434ce

Just download the zip and install it in kodi. Then you'll find the addon under Program addons.

You have of course, to change the IFTT key in the code:

Code:
nano $HOME/.kodi/addons/plugin.program.mylights/addon.py

than change line 19:

Code:
iftt_key = "YOUR_IFTTT_KEY"

So the contents of "YOUR_IFTTT_KEY" is your key.

Cheers
Reply
#8
I really appreciate your effort. But the problem you're trying to solve for me doesn't exist.
I can run the IFTTT scripts from the File manager just fine.

Code:
#!/usr/bin/env python
import subprocess
proc = subprocess.Popen(["curl", "https://maker.ifttt.com/trigger/Turn_off/with/key/enen92"])

The problem I have is to run the other script

Code:
#!/usr/bin/env python
import subprocess
proc = subprocess.Popen("python TDTools_beta.py '--off' '33'", shell=True)

The goal is to run it from the keymap by the way. The IFTTT version works from keymap.

I did try your plugin, but I got "Dependencies not correct" or something similar. The nice looking icon worked though Smile
Reply
#9
If your goal is to run the script through a keymap, you can map the key to the RunScript builtin function. See here:

kodi.wiki/view/keymap
Reply
#10
I use RunScript already and it works with the webrequest script (IFTTT).
But when I try the Python one, nothing.
I'm under the impression that running a script from the File manager or a keymap is identical?

Code:
<keymap>
  <global>
    <keyboard>
    <a mod="ctrl,alt">RunScript(/storage/.kodi/userdata/scripts/light_off.py)</a>
    </keyboard>
  </global>
</keymap>
Reply
#11
Look in your debug log for errors from your script.

Running scripts from the command line is different than running from a keymap. I know this from experience... But I'm not sure if running from the file manager is different too.
Reply
#12
Thanks for the tip on log files. Helped me to find the solution. Because now it works.
It was a problem with the path to the secondary script (TDTools_beta.py). Both the scrips are in the same folder, but that wasn't enough.
So now I can run the light_off script both from the File manager and from keymap!

Solution, add the complete path to the script.

Code:
#!/usr/bin/env python
import subprocess
proc = subprocess.Popen("python /storage/.kodi/userdata/downloads/TDTools_beta.py '--off' '33'", shell=True)
Reply
 
Thread Rating:
  • 0 Vote(s) - 0 Average



Logout Mark Read Team Forum Stats Members Help
Executing a script from Kodi's file manager (solved)00