uilfut
Posts: 72
Joined: Sat Mar 03, 2018 1:20 am
Location: Toronto

running a python script in desktop envirenment remotely

Sat Oct 19, 2019 9:52 pm

Hi there

Hope I can explain this clearly enough.

I use a pi4 to make online gym bookings for me.

I use Selenium to visit the gym's webpage and click the appropriate link.

It works fine but I'd like to be able to start the python script (and pass variables to it) remotely.

I can do it through VNC, but this seems inefficient.

Is there a way I could ssh into the pi and make a script run on the desktop? It's important it's run from the desktop environment as it needs a browser to run (the page uses javascript).

Does this make sense?

User avatar
topguy
Posts: 6491
Joined: Tue Oct 09, 2012 11:46 am
Location: Trondheim, Norway

Re: running a python script in desktop envirenment remotely

Sat Oct 19, 2019 10:26 pm

Does the script start the browser ?

If you just make sure to set the environment variable "DISPLAY" to the value ":0.0" every program you start will know how to "connect" to the desktop.

Code: Select all

#!/bin/bash
export DISPLAY=:0.0
python /home/pi/bookmysweat.py

uilfut
Posts: 72
Joined: Sat Mar 03, 2018 1:20 am
Location: Toronto

Re: running a python script in desktop envirenment remotely

Sun Oct 20, 2019 2:33 am

Thanks v much!

Yes the script starts the browser.

So I just "export DISPLAY=:0.0" and then run my script? This is great if so. Thanks again...

uilfut
Posts: 72
Joined: Sat Mar 03, 2018 1:20 am
Location: Toronto

Re: running a python script in desktop envirenment remotely

Sun Nov 10, 2019 11:20 pm

@topguy

Quick follow up if I may (none of this belongs in advanced users I suspect!)...

How do I tell on the pi whether my phone is currently logged into the pi, running the script?

I've tried "ps" - but this doesn't show an extra user logged in. I'm logging in as my normal "pi" user through the phone interface also.

Thanks again - your export display solution worked perfectly.

Return to “Advanced users”