Legg til ein tilpassa MIME-type for alle brukarar

For å leggje til ein tilpassa MIME-type for alle brukarar på systemet og registrere ein standardapp for han, må du opprette ei ny MIME-typespesifikasjonsfil i mappa /usr/share/mime/packages/ og ei .desktop-fil i mappa /usr/share/applications/.

Legg til ein tilpassa MIME-type application/x-newtype for alle brukarar

  1. Opprett fila /usr/share/mime/packages/application-x-newtype.xml:

    <?xml version="1.0" encoding="UTF-8"?>
    <mime-info xmlns="http://www.freedesktop.org/standards/shared-mime-info">
      <mime-type type="application/x-newtype">
        <comment>ny MIME-type</comment>
        <glob pattern="*.xyz"/>
      </mime-type>
    </mime-info>

    Dømefila application-x-newtype.xml ovanfor definerer den nye MIME-typen application/x-newtype og knyter filnamn med etternamnet .xyz til denne MIME-typen.

  2. Opprett ei ny .desktop-fil, til dømes med namnet myapplication1.desktop, og legg ho i mappa /usr/share/applications/:

    [Desktop Entry]
    Type=Application
    MimeType=application/x-newtype
    Name=My Application 1
    Exec=myapplication1

    Dømefila myapplication1.desktop ovanfor knyter MIME-typen application/x-newtype til ein app som heiter My Application 1, og som vert køyrd med kommandoen myapplication1.

  3. Oppdater MIME-databasen som root, så endringane dine får verknad:

    # update-mime-database /usr/share/mime
            
  4. Oppdater appdatabasen som root:

    # update-desktop-database /usr/share/applications
            
  5. For å stadfeste at du har knytt *.xyz-filer til MIME-typen application/x-newtype, lagar du først ei tom fil, til dømes test.xyz:

    $ touch test.xyz

    Køyr deretter kommandoen gio info:

    $ gio info test.xyz | grep "standard::content-type"
      standard::content-type: application/x-newtype
  6. For å stadfeste at myapplication1.desktop er rett sett som standardapp for MIME-typen application/x-newtype, køyrer du kommandoen gio mime:

    $ gio mime application/x-newtype
    Standard program for «application/x-newtype»: myapplication1.desktop
    Registrerte program:
    	myapplication1.desktop
    Tilrådde program:
    	myapplication1.desktop