You are not logged in.
Hello I want to run a python script on when I launch chromium and I have not idea how to make this possible. Any ideas or advice?
Offline
Use a wrapper script at /usr/local/bin/chromium (or ~/bin/chromium for just your user) that runs the Python script then starts chomium.
Something like
#!/bin/sh
python /path/to/script &
chromium "$@"
The ampersand is only needed if the script needs to be backgrounded before chromium starts.
But unfortunately it looks like chromium.desktop calls the full path in the Exec line so you'll also have to copy that to /usr/local/share/applications/ (or ~/.local/share/applications/ for just your user) and change it to
Exec=/usr/local/bin/chromium
Or just
Exec=chromium
Which should also work for menu entries.
Jin, Jîyan, Azadî
Offline
You could also create a new desktop file in ~/.local/share/applications/ which executes a shell script that starts Python and Chromium.
That way you can keep both regular Chromium and "Python-enhanced" Chromium around as separate app icons in your launcher.
Offline
When I saw this, my first thought was also to create a wrapper. The only other mechanism that came to mind was to create an browser extension that detects startup and runs a script. Not sure of the details on that, and it would not be able to do something before Chromium starts.
What is it you are trying to accomplish? Perhaps this is an X-Y problem, and there may be another way to skin this cat.
Nothing is too wonderful to be true, if it be consistent with the laws of nature -- Michael Faraday
The shortest way to ruin a country is to give power to demagogues.— Dionysius of Halicarnassus
---
How to Ask Questions the Smart Way
Offline
Okay so Im trying to make a custom discord rpc that starts when I run chromium. So this wwas the best idea I came up with.
Offline
Update: I made a working script but when I close chromium the python script still runs how can I make it auto close when closing chromium?
Offline
Assuming you took the above advice, could do the following:
#!/bin/sh
python /path/to/python/script &
pid=$!
chromium "$@"
kill $pid
Of course, a much better approach in my view would be to just make your python script launch chromium, it can then detect when the chromium process exits and the script can finish / exit.
EDIT: sorry for the typo flagged below. I fixed it above.
Last edited by Trilby (2022-01-23 16:34:30)
"UNIX is simple and coherent" - Dennis Ritchie; "GNU's Not Unix" - Richard Stallman
Offline
Assuming you took the above advice, could do the following:
#!/bin/sh python /path/to/python/script & pid=$1 chromium "$@" kill $pid
Of course, a much better approach in my view would be to just make your pythong script launch chromium, it can then detect when the chromium process exits and the script can finish / exit.
I tried this but the python script is still going after I close chromium.
Offline
If I'm not mistaken there is a typo in Trillbys script:
$1 should be $! as it should be the PID of the child and not the scripts first argument.
Edit: added link to documentation
Last edited by lmn (2022-01-23 14:10:04)
Offline
How about
#!/bin/sh
python /path/to/name_of_script &
chromium "$@"
pkill -x name_of_script
Also:
a much better approach in my view would be to just make your python script launch chromium
+1
Jin, Jîyan, Azadî
Offline
How about
#!/bin/sh python /path/to/name_of_script & chromium "$@" pkill -x name_of_script
Also:
Trilby wrote:a much better approach in my view would be to just make your python script launch chromium
+1
I gonna do this instead. How do I make my python script a chromium.desktop file then? Or do I just make the execution go for the python script?
Offline
make the execution go for the python script
^ This.
Jin, Jîyan, Azadî
Offline