-2

I want to set default a specific program for open ANY files absolutely ANY(*.*), any extension, any mime type. ABSOLUTELY ALL

I build a python program to automated choose the program for any file. the app-chooser.py content:

#!/usr/bin/python
import sys, os, os.path
filename = sys.argv[1];
extension = os.path.splitext(filename)[1];

if extension == "txt":
  os.system("gedit " + filename);

if extension == "mp4":
  os.system("vlc " + filename);

if extension == "html":
  os.system("opera " + filename);

if extension == ".py":
  os.system("python " + filename);

if extension == ".sh":
  os.system("bash " + filename);

if extension == ".exe":
  os.system("wine " + filename);

exit()

The app-chooser.py are compiled in a standalone linux executable, located in "/usr/bin/app-chooser".

  • DK Bose you can use like a example gedit to open any file, even if gedit not support that file, gedit always read the file incompatible because the string is the base of any compiled and codified file. you can choose it like a example, if not understand my python program. – vudaluzusa Apr 03 '19 at 03:28
  • Perhaps this question may help you solve your problem. https://askubuntu.com/questions/90214/how-do-i-set-the-default-program – Tech_Person Apr 03 '19 at 03:54
  • Thanks for your comment Tech Person, but unfortunately not works properly for me, because if i use the ubuntu app selector i have to do app by app, and how much filetypes or extensions do you know exist? maybe 10? maybe 25? or thousands of thousands?, in other words, i have to select a default program manually thousands times... and if i do that, then my PROGRAM will be unusable, because im building a app automated selector based on python code. If you know other solution, i will appreciate and read it. – vudaluzusa Apr 03 '19 at 04:22
  • Tech Person, the answer with the content "xdg-mime default " is usable, but wich mime type i have to use for set default ALL FILES open with my program? – vudaluzusa Apr 03 '19 at 05:39
  • example: xdg-mime default app-chooser.desktop */* – vudaluzusa Apr 03 '19 at 05:41
  • N0rbert, i hope i can find a solution in https://askubuntu.com/questions/62585/how-do-i-set-a-new-xdg-open-setting – vudaluzusa Apr 03 '19 at 20:49

1 Answers1

0

You can define a new mimetype for your program:

  1. Create a file e.g. ~/.local/share/mime/packages/application-x-app-chooser.xml with the following content:

    <?xml version="1.0" encoding="UTF-8"?>
    <mime-info xmlns="http://www.freedesktop.org/standards/shared-mime-info">
        <mime-type type="application/x-app-chooser">
            <comment>mime type matching all files with an extension</comment>
            <icon name="application-x-app-chooser"/>
            <glob-deleteall/>
            <glob pattern="*.*"/>
        </mime-type>
    </mime-info>
    
  2. Update the MIME database:

    update-mime-database ~/.local/share/mime
    
  3. Set the .desktop file used to open the matched files:

    xdg-mime default /path/to/file.desktop application-x-app-chooser
    

Using ~/.local/share/mime installs it as a user-specific mime type, replace this path with /usr/share/mime for a system-wide installation.

dessert
  • 39,982
  • Im testing this answer, give me some seconds... – vudaluzusa Apr 03 '19 at 07:41
  • Thank you, im registering this mime type with your code. – vudaluzusa Apr 03 '19 at 08:05
  • ~/.local/share/mime not exist in my version of os, but i already found /usr/share/mime, i will try there.... one sec... – vudaluzusa Apr 03 '19 at 08:12
  • What OS and version are you using? ~/.local/share/mime is the place for user-specific stuff, /usr/share/mime for system-wide. You can safely just create the former if it doesn’t exist yet. – dessert Apr 03 '19 at 08:13
  • Im using, Ubuntu 16 and Debian 10. – vudaluzusa Apr 03 '19 at 09:24
  • Unfortunately, this does not work, the mime type has been registered correctly in "/usr/share/mime/packages", now my program someprogram.desktop linked with the app-chooser.py is visible in the apps selector of nautilus, but when i open any app, the app stuck open with the default application matching the mime, why?, because all files are open using a mime type, not the extension, thanks by your answer. – vudaluzusa Apr 03 '19 at 09:24
  • When i say / i'm including All absolutely Any mime type example in wildcard: (.) means all files, in bash * means all, so i need in mime type be / for mach absolutly ALL MIMES, text, music, video, scripts, documents, images, completely all. – vudaluzusa Apr 03 '19 at 09:25
  • Thanks by you answer and your time. – vudaluzusa Apr 03 '19 at 09:26