My tkinter app should become an URL forwarding app, it selects the browser to take the link, I just can not isolate the system URL parameter

I build a tkinter app that is acting as a default browser.
The problem is that I can not catch the system as it passes the URL
to the default browser:

cmd_param = sys.argv

if len(cmd_param) > 1:
    paramter = cmd_param[1]
else:
    parameter = "itcomserve.de"

I would expect that sys.argv[1] delivers the URL parameter.
but I am just getting an sys.argv[0] wich is the program itself.

any advice on this, I would greatly appreciate, thx in advance … :slight_smile:

detail explanation:

the GUI above produced with pyinstaller, has a list of my browser on my system. I registered this app as my standard browser. As I click an URL on my system e.g. from thunderbird, this program starts and should show that URL as a parameter in the top input field. I was hoping to get this URL parameter by sys.arg, but sys argv provides only sys.argv[0] which is the program itself. sys.argv1 is missing as index.

https://gitlab.com/ycom1/forward2browser/-/tree/master/

Does your application work as expected when you start it manually from command line?

If it works I think the problem is not in your application but in the way your system invokes the “default browser”. We do not even know what is your system and which component takes care of starting the default browser there.

Just an idea for the default browser configuration: Do not you need to specify a placeholder for the URL?

I have looked at your code and at the beginning I noticed that data which should be together are in separate objects (lists):

bname = ["Chromium", "Vivaldi", "Firefox", "Firefox-develop", "Chrome", "Brave", "Basilisk", "Palemoon", "Falkon",
         "Librewolf", "Midori", "Edge"]
bpath = ["", "", "", "", "", "", "", "", "", "", "", ""]
...

It is more logical and it prevents mistakes if you create a structure for the data belonging together. If you do not need to modify such data records later, use NamedTuple:

from typing import NamedTuple

class Browser(NamedTuple):
    name: str
    path: str = ""          # default value
    ...

# Two examples of usage ---

# List of browsers:
browsers = [
        Browser("Chromium"),
        Browser("Vivaldi"),
        Browser("Firefox"),
        ]

# Dictionary of browsers keyed by name:
browsers_by_name = {browser.name: browser for browser in (
        Browser("Chromium"),
        Browser("Vivaldi"),
        Browser("Firefox"),
        )}

The created structures:

[Browser(name='Chromium', path=''),
 Browser(name='Vivaldi', path=''),
 Browser(name='Firefox', path='')]
{'Chromium': Browser(name='Chromium', path=''),
 'Vivaldi': Browser(name='Vivaldi', path=''),
 'Firefox': Browser(name='Firefox', path='')}
2 Likes

yes, when I type e.g. ./fakepybrowser cnn.com it starts with cnn.com in the top input field.
then when I click one of the browsers, it starts also with cnn

If it works I think the problem is not in your application but in the way your system invokes the default browser. We do not even know what is your system and which component takes care of starting the default browser there.

yes I have Linux desktop with KDE plasma, it utilizes xdg for opening standard browser.

I was hoping this comes from the system through that sys.argv[1] pass
but really it does not. But when I type the command
./fakepybrowser cnn.com then sys.argv[1] points to cnn.com and appears
also in the field.

def init_browser_list():
    browser_list = ["Chromium", "Vivaldi", "Firefox", "Firefox-develop", "Chrome", "Brave", "Basilisk", "Palemoon",
                    "Falkon", "Librewolf", "Midori", "Edge"]
    init_dict = {"browser_name": [], "browser_path": []}
    for browser in browser_list:
        init_dict["browser_name"].append(browser)
        init_dict["browser_path"].append(browser.lower())
        # print('init dictionary:'+str(init_dict))
        file_content = "browsers = " + str(init_dict)
        # print('file content:'+file_content)
        with open("browsers.json", "w") as file_target:
            json.dump(init_dict, file_target)

that is how my browser list is initialized.

ALSO THANK YOU SO MUCH YOU ARE LOOKING INTO IT : - )
I AM STRUGGLING SINCE 2 WEEKS WITH THIS …
**all along trying browser, URL, … modules to get that answer from **
the XDG (sub?)system …

Go to KDE System settings.

Choose “Applications” and in “Standard applications” the entry for Webbrowser. As a command specify your applications name and I think %u for the url.

HTH

3 Likes

YOU ARE THE BEST , that worked !!! :grinning::-):-):slight_smile:
THANK YOU SO MUCH, that %u thingy was missing