Python file association

So,

I want to do the following with python files (.py) from the native file doohicky:

  1. If I double click on the file, I want to run it in python3
  2. If I right click on the file, I'd like to pick a suitable application to open the file, for that instance only (file editor, NOT gnome, Geany, etc)

How, exactly, do I do this?

thank you,

chris

This is an old thread and 'gksudo' is now deprecated:

So,

Short answer, not really possible? :thinking:

Hi, not sure, I am no coder. Just trying to help out where I can. Perhaps someone with Python experience could chip in. Anyone?

The only way I know how to do this is by creating a .destkop file. This type of file has a special syntax that tells the system how to launch a particular program or script. You can use this to create your own launchers for specific websites on a web browser, for example.

So you can create a file named something like "my_script.desktop" with the following contents:

[Desktop Entry]
Name=MyScript
Comment=Some description
Exec=/path/to/where/the/script/lives/script.py
Path=/path/to/where/the/script/lives/
Icon=/path/to/some/icon.png
Terminal=false
Type=Application
Categories=Utility;

Some fields, like the Icon, are optional.

If you place this file in /usr/share/applications or ~/.local/share/applications you will find it in the Zorin Menu as well, so it's even easier to launch.

But this isn't a file association, you'd still have to do this for each script. Although I would argue that if you really need to double-click on too many scripts, this is what you want to do anyway.

For reference: Desktop entries - ArchWiki

This topic was automatically closed 90 days after the last reply. New replies are no longer allowed.