Running Python Programmes on the Lego EV3 via the EV3 File Browser

A quick note to self… If we test python scripts on an EV3 brick interactively via a Jupyter notebook and then save the notebook as a python file (eg Untitled1.py), we can get the Python file over to the EV3 brick and into a state we can run it from the file browser by using the following recipe:

echo '#!/usr/bin/python'|cat - Untitled1.py > /tmp/out && mv /tmp/out Untitled1.py
scp Untitled1.py robot@192.168.1.106:/home/robot/
ssh robot@192.168.1.106 'chmod ugo+x /home/robot/Untitled1.py'

Then in the file browser on the brick, just click on Untitled1.py to run it.

It would be easy enough to script this so a single button in the notebook does it automatically? (In which case, it would probably make more sense to modify the template used to generate the Python save file so that it includes the shebang at the start of the file anyway?)

PS see also Setting Up PyCharm To Work With a Lego Mindstorms EV3 Brick and Sharing Files With a Lego EV3 Brick Over Wifi Using Filezilla.