Gotham run shell script via keyboard shortcut?
#1
Hello

I am trying to run a .sh shell script in OpenElec Gotham via a keyboard shortcut Ctrl+Alt+A

I just tried adding these two lines in to the XBMC keyboard.xml file and rebooting

<A mod="ctrl,alt">System.Exec(/storage/.xbmc/userdata/vera/lounge-on.sh)</A>
<B mod="ctrl,alt">System.Exec(/storage/.xbmc/userdata/vera/lounge-off.sh)</B>

But nothing happens and the script(s) are not run when I initiate the keyboard shortcuts. XBMC can also sometimes hang when I press the keyboard shortcuts.

I know the modifier <A mod="ctrl,alt"> works if I put in an XBMC function instead like to open the Music window, then when pressing the keyboard shortcut that action is carried out OK.

The scripts run OK in SSH terminal using this command: sh lounge-on.sh

I've searched the forums but no luck getting it working. Any ideas?

Many thanks
Reply
#2
It works in Windows 7 OK with these two lines in the keyboard.xml file. Had to use double quotes however.

<A mod="ctrl,alt">System.Exec(""C:\Program Files (x86)\XBMC_GOTHAM\portable_data\userdata\vera\Lounge-On.cmd"")</A>
<B mod="ctrl,alt">System.Exec(""C:\Program Files (x86)\XBMC_GOTHAM\portable_data\userdata\vera\Lounge-Off.cmd"")</B>

When I enter the keyboard shortcut XBMC is minimized whilst the .cmd file is run and then maximized again, would be better if XBMC stayed full screen and it just ran the .cmd files in the background?

I can't seem to setup a similar thing in Linux / OpenElec though.
Reply
#3
If I try and add quotes to the Linux code lines

<A mod="ctrl,alt">System.Exec("/storage/.xbmc/userdata/vera/lounge-on.sh")</A>
<B mod="ctrl,alt">System.Exec("/storage/.xbmc/userdata/vera/lounge-off.sh")</B>

When I press the keyboard shortcut XBMC just quits and then restarts and I don't think the script is run.

I can't see anything relating to this in the XBMC debug log file either.

I've also tried adding XBMC in front like XBMC.System.Exec but it makes no difference.
I've also tried moving my scripts in to the root of the /storage folder and that makes no difference either

<A mod="ctrl,alt">XBMC.System.Exec("/storage/lounge-on.sh")</A>
<B mod="ctrl,alt">XBMC.System.Exec("/storage/lounge-off.sh")</B>
Reply
#4
I have it working now but its a bit convoluted.

I created a python script called lights-on.py containing this code:

Code:
#!/usr/bin/env python
import os
bashCommand = "/bin/bash /storage/.xbmc/userdata/vera/lounge-on.sh"
os.system(bashCommand)

This python script executes my shell script lounge-on.sh

In the XBMC keyboard.xml file I am now using the RunScript

<A mod="ctrl,alt">RunScript(/storage/.xbmc/userdata/vera/lounge-on.py)</A>

and when I press the keyboard shortcut this launches the python script that in turn then runs the .sh shell script and the shell script runs a curl command to send a http request to my Home Automation system to turn the lights on.

Man there must be a better way of doing this, my programming sucks. Maybe I can run the curl command in the python script and do away with the shell script altogether.

I can now program my Logitech Harmony remote to send the Ctrl+Alt+A command turning it in to a Z-wave remote via the XBMC PC.
Reply
#5
If you need to run your scripts with bash or sh, like
Code:
bash /path/to/script.sh
rather than just
Code:
/path/to/script.sh
then either (a) your script is not executable or (b) you forgot to put the line #!/bin/sh on the first line of your script.
If I have helped you or increased your knowledge, click the 'thumbs up' button to give thanks :) (People with less than 20 posts won't see the "thumbs up" button.)
Reply
#6
Hi Nick

Thanks for the reply.

When ever I use System.Exec XBMC either quits and then restarts or just hangs and the script is not run and the lights do not turn on etc.

I just tried this line in the keyboard.xml file:

<A mod="ctrl,alt">System.Exec(bash /storage/.xbmc/userdata/vera/lounge-on.sh)</A>

And this is my lights-on.sh script:

Code:
#!/bin/sh
curl "http://192.168.1.100:3480/data_request?id=lu_action&output_format=xml&DeviceNum=16&serviceId=urn:upnp-org:serviceId:SwitchPower1&action=SetTarget&newTargetValue=1"

I have also made the script executable using the command:

chmod +x lounge-on.sh


I am wondering if I can just run the curl http command directly in a python .py script instead and use the RunScript rather than System.Exec in the Keyboard.xml and do away with the .sh shell script files altogether.

Thanks
Reply
#7
Hi

This python script works:

Code:
#!/usr/bin/env python
import subprocess
proc = subprocess.Popen(["curl", "http://192.168.1.100:3480/data_request?id=lu_action&serviceId=urn:micasaverde-com:serviceId:HomeAutomationGateway1&action=RunScene&SceneNum=1"])

When I run this python script in terminal it turns on my lights.

So in the XBMC keyboard.xml file I can just use RunScript and call this python script.

This means I no longer need the .sh shell script files at all and can do away with them.
Reply
#8
(2014-05-31, 14:02)cw-kid Wrote: I just tried adding these two lines in to the XBMC keyboard.xml file and rebooting

<A mod="ctrl,alt">System.Exec(/storage/.xbmc/userdata/vera/lounge-on.sh)</A>


Hi cw-kid, have you tried:

<A mod="ctrl,alt">System.Exec("/storage/.xbmc/userdata/vera/lounge-on.sh")</A>

That's how I run bash scripts from my keyboard.xml and they do work.
Reply
#9
(2014-07-24, 18:45)hamradio Wrote:
(2014-05-31, 14:02)cw-kid Wrote: I just tried adding these two lines in to the XBMC keyboard.xml file and rebooting

<A mod="ctrl,alt">System.Exec(/storage/.xbmc/userdata/vera/lounge-on.sh)</A>


Hi cw-kid, have you tried:

<A mod="ctrl,alt">System.Exec("/storage/.xbmc/userdata/vera/lounge-on.sh")</A>

That's how I run bash scripts from my keyboard.xml and they do work.

Hi

I used .py python script files in the end and didn't need to use .sh shell script files which were problematic launching. I did try using System.Exec to launch .sh scripts but XBMC would hang or crash.

I used a line like the one below in the XBMC keyboard.xml file to link the python scripts to a particular keyboard shortcut such as Ctrl+Alt+A

Code:
<A mod="ctrl,alt">RunScript(/storage/.xbmc/userdata/vera/mbed-lightson.py)</A>

I basically wanted to be able to program my Logitech Harmony remote control with these keyboard shortcuts and then have XBMC launch the python script when I pressed the button on the remote, in turn the python script would then send a http request to my home automation controller using curl to do something like turn on a light. It works really well I wrote about my setup here and part 2 here.
Reply
#10
(2014-05-31, 18:02)cw-kid Wrote: I have it working now but its a bit convoluted.

I created a python script called lights-on.py containing this code:

Code:
#!/usr/bin/env python
import os
bashCommand = "/bin/bash /storage/.xbmc/userdata/vera/lounge-on.sh"
os.system(bashCommand)

This python script executes my shell script lounge-on.sh

In the XBMC keyboard.xml file I am now using the RunScript

<A mod="ctrl,alt">RunScript(/storage/.xbmc/userdata/vera/lounge-on.py)</A>

and when I press the keyboard shortcut this launches the python script that in turn then runs the .sh shell script and the shell script runs a curl command to send a http request to my Home Automation system to turn the lights on.

Man there must be a better way of doing this, my programming sucks. Maybe I can run the curl command in the python script and do away with the shell script altogether.

I can now program my Logitech Harmony remote to send the Ctrl+Alt+A command turning it in to a Z-wave remote via the XBMC PC.


Thanks for posting your solution!
still works on Kodi 15.2 / fedora 23

This can be integrted into Kodi's GUI using the "Commands" addon. Using this combination to replace the unsupported "advancedLauncher" that started to misbehave recently.
Reply
#11
Full details can be seen here for my final solution

http://windowsmediacenter.blogspot.co.uk...rmony.html

You can do it with just a .py file and get rid of the .sh script file.

I used this to turn my Harmony remote in to a controller for my Home Automation system via the Openelec HTPC.
Reply
#12
@htpcero

So you are saying you are able to create a button / menu item in the Kodi GUI which when selected will run one of the .py commands ?

How do you do this ?

Cheers
Reply
#13
(2015-12-10, 11:06)cw-kid Wrote: @htpcero

So you are saying you are able to create a button / menu item in the Kodi GUI which when selected will run one of the .py commands ?

How do you do this ?

Cheers

Nearly so. I have a shortcut icon under Programs for the Commands addon. When launched it presents a list with the scripts. You can select any from the list and launch it.

The Commands addon allows you to launch any Kodi command, including RunScript(). I use this in Fedora to launch terminal-based scripts, open chrome and show monitorix graphs, etc.
Reply

Logout Mark Read Team Forum Stats Members Help
Gotham run shell script via keyboard shortcut?0