I am trying to make a shell script execute using a shortcut on my keyboard, but i have a feeling that System.Exec just doesnt work.
Is it included in OSMC ? Normal keymappings work…but i just can get System.Exec to execute scripts.
Yeah thanks, i totally forgot about that.
Kodi freezes though after i execute it now.
Although the script starts the command i want it seems that the whole GUI hangs.
Executing sudo /etc/init.d/vncboot start from the console works fine though.
I’ll look more into it.
Its not really a service…but a script. I’ve never used systemd before to tell you truth. I am a small time CentOS, Debian user…This is all Greek to me (and i am Greek lol).
I basically wanted to have a script tied to a button to start/stop vnc server. the vncboot script is just a switch basically.
I made a file called vncboot inside /etc/init.d/.
Then chmod +x /etc/init.d/vncboot My vncboot:
#!/bin/sh
# /etc/init.d/vncboot
### BEGIN INIT INFO
# Provides: vncboot
# Required-Start: $remote_fs $syslog
# Required-Stop: $remote_fs $syslog
# Default-Start: 2 3 4 5
# Default-Stop: 0 1 6
# Short-Description: Start VNC Server at boot time
# Description: Start VNC Server at boot time.
### END INIT INFO
VNCUSER='osmc'
PROGRAMBIN="dispman_vncserver"
PIDOFPROGRAMBINCMD="pidof $PROGRAMBIN"
PIDOFPROGRAMBIN=`eval $PIDOFPROGRAMBINCMD`
PROGRAMSTR="dispman_vncserver"
eval cd ~$VNCUSER
case "$1" in
start)
sudo modprobe uinput
sudo chmod 666 /dev/uinput
su $VNCUSER -c '/usr/bin/dispman_vncserver'
#echo "Starting dispman_vncserver server for $VNCUSER "
;;
gui)
if [ "x$PIDOFPROGRAMBIN" != "x" ] ; then
echo "Closing $PROGRAMSTR"
sudo ps aux | grep "dispman_vncserver" | grep -v grep | awk '{print $2}' | xargs sudo kill -9
else
echo "Starting $PROGRAMSTR..."
sudo modprobe uinput
sudo chmod 666 /dev/uinput
sudo dispman_vncserver
fi
;;
stop)
sudo ps aux | grep "dispman_vncserver" | grep -v grep | awk '{print $2}' | xargs sudo kill -9
#echo "dispman_vncserver stopped"
;;
*)
echo "Usage: /etc/init.d/vncboot {start|gui|stop}"
exit 1
;;
esac
exit 0
Using this keymap.xml file (from /home/osmc/.kodi/userdata/keymaps)
make sure the owner/group are the pi user (or osmc, cant remember…check with a console command to see the rest of the files)
Also do chmod +x YOUR_SH_FILE
and finally make sure you have sudo blah blah infront of every command like for example:
vncon.py
import os
os.system(‘sudo /etc/init.d/vncboot gui’)
because maybe the command is executed but just doesnt have the rights to really execute.
also single quotes and double quotes make a difference…try switching what you have now…I think single quotes is for the python scripts, and double quotes for the keymap commands (when it comes to executing shell commands)
I ended up not using any here: RunScript(/home/osmc/vnc/vncon.py) just for that reason…in the end i removed them just to make sure.
“system paths” are a shell feature. If you execute a program directly using something like os.system() without running it inside a shell then there are no system paths, so you must specify the paths explicitly.
It’s generally good practice in these kind of circumstances to always provide the full path to the program because even if you do run the command within a shell, different users (osmc, root and so on) typically have different paths as well.