I wanted to be able to trigger a PowerShell script with an argument from the Kodi menu…
eg. TriggerScript.ps1 -namedArg
1st – Create a python script (eg. triggerscript.py) in the home directory (/home/osmc/) containing the following:
# -*- coding: iso-8859-1 -*- import subprocess, sys, requests localurl = "http://localhost/jsonrpc" headers = {'Content-type': 'application/json'} mydata = {'id':'1','jsonrpc':'2.0','method':'GUI.ShowNotification','params':{'title':'Initiating PowerShell','message':'Starting ' + sys.argv[1] +' Script...','displaytime':13000}} response = requests.post(localurl, data=None, json=mydata) p = subprocess.Popen(["pwsh","/home/osmc/TriggerScript.ps1","-Action",sys.argv[1]],stdout=subprocess.PIPE) p.communicate()
2nd – Within Kodi, in the Skin Editor, Create a custom action:
RunScript(/home/osmc/triggerscript.py,namedArg)
Note: You have two methods to check whether this will work (use from home location):
RunScript(/home/osmc/triggerscript.py,namedArg) python triggerscript.py namedArg