pcmanfm - How to set the preferred order of "open with" ?

Do you have a question? Post it now! No Registration Necessary

Translate This Thread From English to

Threaded View
Hello all,

Currently I can rightclick a python source file and than select an  
application to open it with.   Is there a way to change the order of this  
list ?    I would like to put a text editor on top, followed by Thonny (for  
both python as well as python3 shebanged files).

Yes, I did my due duty by first trying to google it, but somehow I (again)  
can't find much of anything about it (most of the stuff is more than 5 years  
old).

Looking at my own stuff,  I have python files (with the shebang line "#!  
/usr/bin/env python"), which shows "Geany", "Thonny", "Text editor" and  
"Libre Office writer" in that order.   I would like to get rid of the "Libre  
office writer" entry entirely (and possibly "geany" too) , and have the  
"Text editor" and "Thonny" in that order as the first two.

I also have python3 files (with the shebang line "#! /usr/bin/env python3")  
which shows the same list, but with "mu" added to the top.   Same problem.  
"Text editor" and 'Thonny" as the first two, and we can talk about the rest.  
:-)

One of my problems is that I've searched, starting from "/usr", for all  
"*.desktop" files containing "python", and have not found either "Text  
editor" nor "Libre office writer" among them.   The same search using  
"python3" added "Geany" to be absent.

In short, I have no idea how "Text editor", "Geany" and "Libre office  
writer" become part of the "open with" list for the above two python version  
files.

hmmm.... A quick check of my .sh, .c  and .h files show that "Libre office  
writer" thinks it has some right to those filetypes too - even though the  
"libreoffice-writer.desktop" file mentions none of them.  :-(

tl;dr:

So, how do I
(primary) sort the entries in the "open with" list ?
(secondary) get rid of certain "open with" entries - especially when their  
.desktop configurations do not mention the files mimetype ?

Regards,
Rudy Wieser



Re: pcmanfm - How to set the preferred order of "open with" ?
  To: R.Wieser
 > From Newsgroup: comp.sys.raspberry-pi

 > Hello all,

 > Currently I can rightclick a python source file and than select an
 > application to open it with.   Is there a way to change the order of this
 > list ?    I would like to put a text editor on top, followed by Thonny (for
 > both python as well as python3 shebanged files).

 > Yes, I did my due duty by first trying to google it, but somehow I (again)
 > can't find much of anything about it (most of the stuff is more than 5 years
 > old).

 > Looking at my own stuff,  I have python files (with the shebang line "#!
 > /usr/bin/env python"), which shows "Geany", "Thonny", "Text editor" and
 > "Libre Office writer" in that order.   I would like to get rid of the "Libre
 > office writer" entry entirely (and possibly "geany" too) , and have the
 > "Text editor" and "Thonny" in that order as the first two.

 > I also have python3 files (with the shebang line "#! /usr/bin/env python3")
 > which shows the same list, but with "mu" added to the top.   Same problem.
 > "Text editor" and 'Thonny" as the first two, and we can talk about the rest.
 > :-)

 > One of my problems is that I've searched, starting from "/usr", for all
 > "*.desktop" files containing "python", and have not found either "Text
 > editor" nor "Libre office writer" among them.   The same search using
 > "python3" added "Geany" to be absent.

 > In short, I have no idea how "Text editor", "Geany" and "Libre office
 > writer" become part of the "open with" list for the above two python version
 > files.

 > hmmm.... A quick check of my .sh, .c  and .h files show that "Libre office
 > writer" thinks it has some right to those filetypes too - even though the
 > "libreoffice-writer.desktop" file mentions none of them.  :-(

 > tl;dr:

 > So, how do I
 > (primary) sort the entries in the "open with" list ?
 > (secondary) get rid of certain "open with" entries - especially when their
 > .desktop configurations do not mention the files mimetype ?

 > Regards,
 > Rudy Wieser

Here's a good place to start ...
https://developer.gnome.org/integration-guide/stable/desktop-files.html.en
--- Synchronet 3.17c-Win32 NewsLink 1.110
Alleycat! BBS - telnet://alleycat.synchro.net

Re: pcmanfm - How to set the preferred order of "open with" ?
Gregg,

Quoted text here. Click to load it

I already know the relevant part (mimetypes) of those .desktop files, and am  
aware that I can remove mimetypes from the relevant entries to make them  
disappear from the "open with" list.

The problem is that some applications (Libre office writer, geany) appear in  
such "open with" list even though they do not show to support the mimetype  
of the file.   I do not see any thing in that regard.

Also, the main problem, the word "sort" appears exactly once in that  
document (in the second paragraph), and gives no information how to  
influence the order of items in a "open with" list.

The word "mime" appears twice, once in a "its supposed to handle this too"  
line but with no further information, and once in a link - which (rather  
tersely) mentions how you create hem, but nothing about managing them.

Thanks for trying though.

Regards,
Rudy Wieser



Re: pcmanfm - How to set the preferred order of "open with" ?
declaimed the following:


Quoted text here. Click to load it

    Part of this may come back down to "file"...

pi@rpi3bplus-1:~$ file -k -r  *.py
test1.py: Python script text executable Python script, ASCII text
executable
-
test2.py: Python script text executable
- a /usr/bin/python3 script text executable Python script, ASCII text
executable
-
tst.py:   ASCII text
-
pi@rpi3bplus-1:~$


    Note how all three have the tag "ASCII text"... That likely triggers
any application that handles "text/plain".

    As for Geany -- since you manage to have file return text/x-python3 for
some files, you may have to add that to the geany.desktop to get it to show
for those files.

    I suspect you can't reorder the list -- it's either alphabetical (based
upon some field in the .desktop file) or it's the order the .desktop files
were scanned when building the menu.


--  
    Wulfraed                 Dennis Lee Bieber         AF6VN
     snipped-for-privacy@ix.netcom.com    http://wlfraed.microdiversity.freeddns.org/

Re: pcmanfm - How to set the preferred order of "open with" ?
Dennis,

Quoted text here. Click to load it

I'm sorry, but I don't get that.   I've gotten the idea that the desktop and  
pcmanfm have their own way to determine a mimetype (as returned by "xdg-mime  
query filetype"), but suddenly now the output of "file -k -r" / "file -i"  
becomes relevant again ?    What the blases is going on there ?    How am I  
to make sense of that ?

Quoted text here. Click to load it

No.   It would mean that whomever wrote pcmanfm made a mess of things, and  
that I do not (yet) believe.

Quoted text here. Click to load it

Definitily not alphabetical, as I've seen 'Text editor" below "Thonny",  
"LibreOffice writer" below "Text editor" and "Geany" below "mu".

Quoted text here. Click to load it

... and sometimes ordered differently.  Like a .c file having "Geany" and  
than "Text editor", but a .txt file having them in the reverse order.

In other words, /something/ is influencing the order of the "open with"  
entries - likely based on the files mimetype (but thats a guess).



As I could not find much of anything, I decided to remove the "mime-type="  
line from the "/usr/share/applications/libreoffice-writer.desktop" file (and  
calling "update-mime-database" just in case) and rebooting, but the  
"libreoffice writer" entry was still there in the "open with" list. :-\  
Any idea (what program I should use to get the changes I made accepted by  
pcmanfm - if that is what it takes that is) ?

I've also spend quite a bit more time googeling, but have not found anything  
further.  Other than someone, years ago, saying that info on what I want/try  
to do should be easily findable.  Yeah, right :-|

I'm a bit put-off to be honest: Even the simpelest of things in relation to  
the desktop and filebrowser (creating a desktop shortcut with icon, adding a  
filetype, changing an "open with" list) are schrouded in  
things-you-just-have-to-know, as related information is only sparsely and  
fragmented available - if at all. :-(

Not funny, not funny /at all/.

Regards,
Rudy Wieser



Re: pcmanfm - How to set the preferred order of "open with" ?

    Following up...

declaimed the following:

Quoted text here. Click to load it

pi@rpi3bplus-1:~$ grep -r -i "text/plain" /usr/share/mime/* |grep "python"
/usr/share/mime/subclasses:text/x-python text/plain
/usr/share/mime/text/x-python.xml:  <sub-class-of type="text/plain"/>
pi@rpi3bplus-1:~$

    From which I deduce that any application that handles text/plain will
be considered valid for text/x-python (I still have no idea why
text/x-python3 is so irregular on this system -- it shows up in some files
but not others).

    You might want to study the contents of the directory /user/share/mime


    AH -- there it may be...
pi@rpi3bplus-1:~$ cat /usr/share/mime/text/x-python3.xml
<?xml version="1.0" encoding="utf-8"?>
<mime-type xmlns="http://www.freedesktop.org/standards/shared-mime-info "
type="text/x-python3">
  <!--Created automatically by update-mime-database. DO NOT EDIT!-->
  <comment>Python 3 script</comment>
<SNIP>
  <sub-class-of type="text/x-python"/>        <====== and x-python is
  <glob weight="50" pattern="*.py"/>
  <glob weight="60" pattern="*.py3"/>
  <glob weight="60" pattern="*.py3x"/>
</mime-type>
pi@rpi3bplus-1:~$

pi@rpi3bplus-1:~$ cat /usr/share/mime/text/x-python.xml
<?xml version="1.0" encoding="utf-8"?>
<mime-type xmlns="http://www.freedesktop.org/standards/shared-mime-info "
type="text/x-python">
  <!--Created automatically by update-mime-database. DO NOT EDIT!-->
  <comment>Python script</comment>
<SNIP>
  <sub-class-of type="application/x-executable"/>
  <sub-class-of type="text/plain"/>        <=======
  <glob weight="60" pattern="*.py"/>
  <glob weight="60" pattern="*.pyx"/>
  <glob weight="60" pattern="*.wsgi"/>
</mime-type>
pi@rpi3bplus-1:~$


--  
    Wulfraed                 Dennis Lee Bieber         AF6VN
     snipped-for-privacy@ix.netcom.com    http://wlfraed.microdiversity.freeddns.org/

Re: pcmanfm - How to set the preferred order of "open with" ?
Dennis,

Quoted text here. Click to load it

Sounds reasonable.  So, I removed all lines mentioning "python" (3 or 4),  
updated the database and rebooted (for good measure).  Alas, no change in  
the contents or order of the "open with" list of either a python or python3  
list.   Absolutily nothing ...

Quoted text here. Click to load it

No.  Currently I'm getting a bit tired of this guessing game, and instead  
want to find/have information.  Sorry.

Quoted text here. Click to load it

The contents of those files (in the "text" folder) get generated by updating  
the mime database.   Hence the actual info must be somewhere else.   Where ?  
Your guess is as good as mine I'm afraid.

And those weights ?   Those /could/ have something to do with the ordering  
in the "open with" list.  But again, thats just guessing (already tried  
googeling for it).   And thats apart of how they get determined, 'cos its  
certainly not in the xml mimetype definition file.

Lets hope that I will look differently at it tomorrow ...

Regards,
Rudy Wieser



Re: pcmanfm - How to set the preferred order of "open with" ?
declaimed the following:


Quoted text here. Click to load it

    Unfortunately, that is going to require a LOT of Google (and man page)
searches, trying various keywords.

    For example, finding out how update-mime-database works led me to

https://www.linuxtopia.org/online_books/linux_desktop_guides/gnome_2.14_admin_guide/mimetypes-database.html

This was in the midst of playing with the sequence of operations shown
next, when I encountered a file that said DO NOT EDIT and that was
generated by the update command.:

-=-=-=-
<right click on test2.py>
Open With >
    Geany
    Thonny Python IDE
    Text Editor
    gVim
    Vim
    LibreOffice Writer

pi@rpi3bplus-1:~$ sudo vim /usr/share/applications/mousepad.desktop  
Change
    GenericName=Text Editor
To
    GenericName=MousePad
{Also changed the [en_AU] and [en_GB] lines}

No immediate change on menu

pi@rpi3bplus-1:~$ sudo vim /usr/share/applications/gvim.desktop
Added gVim to genericname (no effect)
Added
    ;Development
to Categories

gVim now shows up on Programming menu (beside on Accesories)

    {here's where the update-mime-database search led me}
pi@rpi3bplus-1:~$ sudo vim /usr/share/mime/packages/freedesktop.org.xml  
Commented out     
      <!--<sub-class-of type="text/plain"/>-->
for the text/x-python section; but left text/x-python3 as sub-class of
text/x-python
  
pi@rpi3bplus-1:~$ sudo update-mime-database /usr/share/mime

<right click on test2.py now shows ONLY>
Open With >
    Geany
    Thonny Python IDE

    Removing the text/plain subclass removed all the generic text editors

pi@rpi3bplus-1:~$ sudo vim /usr/share/applications/gvim.desktop
Added
    text/x-python;
to end of MimeTypes list

No change to right click menu; REBOOT
Still no change on menu; getting specific entries back is the next step

<right click test2.py [which has python3 shebang and text/x-python3 type]>
Open with >
    Open with...
        Selected gVim and [X]Set selected ... default


<right click test1.py [no shebang, text/x-python type]>
Do same.

<right click any .py now shows>
Open With >
    gVim
    Geany
    Thonny Python IDE

Redid (on both .py file) Open with.../selected Thonny and [X]Set selected
...

<right click any .py now shows>
Open With >
    Thonny Python IDE
    gVim
    Geany

Reboot to see if setting stays

It did (at least once)...
-=-=-=-

    So... It looks like I was able to "resort" the Open With > menu. It
required using the Open with... sub-menu, [X] the Set selected flag, and
select the one you want last (it will become the top). Repeat with each
candidate so the previous selections get pushed down.

    You have to do this for each different MIME type the files are
identified as (eg; python vs python3).

NOTE: I'm still running the default file manager for Raspbian, which I
believe is Thunar. Don't know if the one you are running will behave the
same way.


--  
    Wulfraed                 Dennis Lee Bieber         AF6VN
     snipped-for-privacy@ix.netcom.com    http://wlfraed.microdiversity.freeddns.org/

Re: pcmanfm - How to set the preferred order of "open with" ?
Dennis,

Quoted text here. Click to load it

First off, my apologies for having put it that blunt.   You've been nothing  
than helpfull to me.   But after having done my best for a number of days  
and gotten nowhere I was near to just dropping (almost literally) the whole  
(Raspberry Pi) thing.

Quoted text here. Click to load it

I've been scouring the web for any-and-all info I could find for days now -  
only to find stuff thats 5 years or more old (likely not applicable  
anymore/to rapbian) from others wanting to know the same.   No answers.

Quoted text here. Click to load it

I found similar, but saw that those and yours alike stop where the jucy bit  
is supposed to start::  There is /no/ information about how the information  
in there causes stuff to happen.  In short, I can change stuff in that file,  
but have zero idea what it actually results in.

And by the way, that last line there is right, but rather incomplete.  
Remember those files in the /usr/share/mine/text folder you found stuff in ?  
Those also get rewritten.  As do a few others.   Making changes in them  
might look like a good idea, but on call to the database updater program and  
they are gone. :-\

Quoted text here. Click to load it

:-) I was not even looking at that (just the "open with" list you see  
directly after rightclicking), but thats a nice find.   It shows how the  
grouping works.

Quoted text here. Click to load it

:-) You found it too.  It was only after I took a peek in it that I realized  
that that one is where the file-to-mimetype translation is taking place.  
And yes, I've already been playing in it too.  As a result I've given both  
the python and python3 sourcefiles the same "Thonny", "Geany" order.

I already had the idea, if all else would fail, to change the name of the  
"text/x-python" mimetype name to something else, and see how far I could go  
(hey, a single change there ?  That /should/ be easy to follow, right ? :-)

Quoted text here. Click to load it
....

I assumed that that would happen, but wanted tho keep the "Text editor"  
choice in the list.  And, if I get my way, as the first entry (with, for  
Python, "Thonny" as the second).

Quoted text here. Click to load it

Thats a good one!  I did not assume that the "open with" list would contain  
the preferred-open-by entry.

Quoted text here. Click to load it

:-)  I think you've solved my problem there.  Thanks.

And even without needing to dig deep into Linux innards and edit  
configuration files !

Though I wil probably visit those innards anyway, just to see if-and-how I  
can get those changes by editing config files - just to see if I can.

Quoted text here. Click to load it

The same here.

Quoted text here. Click to load it

I think that the name of my file manager is "pcmanfm".  At least, I've been  
using "sudo pcmanfm" for a while now to easily access and be able to edit  
the files in the /user/share/mime (and other) subtrees.

Quoted text here. Click to load it

There is only one way to know ...  Yep, it looks like it.

Furthermore, it survives an update-mime-database call (just thought to do a  
quick test).

... Though I tried to open a Scratch2 project (dont ask) with the "text  
editor", and now its a permanent entry in that list. :-|

Which means I will most likely have to do that digging anyway. :-)

Thanks for your help.

Regards,
Rudy Wieser



Re: pcmanfm - How to set the preferred order of "open with" ?
declaimed the following:

Quoted text here. Click to load it

    To be fair, Applications/Preferences Main Menu Editor gives a graphical
way to edit the main menu, including reordering entries (just spotted it
while looking for something else: Debian xfce has a "Mime Types Editor",
but does not have a Menu Editor)

Quoted text here. Click to load it

    Suspect you could specify it on the .config/mimeapps.list (I think the
common "Text Editor" is mousepad.desktop). Commenting out the text/plain
subclass for text/x-python meant LibreOffice doesn't come near it <G>

{I also discovered that GNAT Programming Studio sticks its icon file in a
non-standard location, so I had to put in the full path for the icon on its
.desktop file. Now the menu shows the GNAT "G"}

Quoted text here. Click to load it

    Still a touch faster (especially if you have multiple types to work
with) to hand edit the .config/mimeapps.list file...

Quoted text here. Click to load it
    Okay -- too many OSs here (and I haven't even attempted to use the
graphical environment on the BeagleBone Black, which is LXQT). xfce uses
Thunar.

Quoted text here. Click to load it

    Open With... seems to add whatever one picks. Just that, unless [X] Set
selected was picked, it does not become the default for double-clicking.


--  
    Wulfraed                 Dennis Lee Bieber         AF6VN
     snipped-for-privacy@ix.netcom.com    http://wlfraed.microdiversity.freeddns.org/

Re: pcmanfm - How to set the preferred order of "open with" ?
On Tue, 12 Nov 2019 17:56:26 +0100

Quoted text here. Click to load it

    Just one thing, as far as I can see your problems have nothing to
do with the Raspberry Pi but rather with the brain dead configuration
arrangements in modern unix desktop environments.

--  
Steve O'Hara-Smith                          |   Directable Mirror Arrays
C:\>WIN                                     | A better way to focus the sun
We've slightly trimmed the long signature. Click to see the full one.
Re: pcmanfm - How to set the preferred order of "open with" ?
Ahem,

Quoted text here. Click to load it

You're right there ofcourse.  The problem is neither the Raspberry Pi, nor  
the Linux kernel.  Though as the desktop and the filebrowser function as a  
(GUI) bottleneck to the underlying system ...

Regards,
Rudy Wieser



Re: pcmanfm - How to set the preferred order of "open with" ?
Quoted text here. Click to load it

Ah, a light bulb moment for you. Before long you'll done away with a GUI  
desktop completely - maybe even run headless :-) and enjoy the freedom.  

Goodluck
Jim

Re: pcmanfm - How to set the preferred order of "open with" ?
Jim,

Quoted text here. Click to load it

:-) you wish.

Quoted text here. Click to load it

Don't bet on that.   I'm not religious either way.

And by the way, what makes you (among others) think I do not have experience  
with the CLI (Linux or otherwise) ?

... or is that a required presumption for Linux users ? :-p

Regards,
Rudy Wieser  



Re: pcmanfm - How to set the preferred order of "open with" ?
Quoted text here. Click to load it

Sadly, experience does tend to that view of people coming to Linux from  
Windows. I hope yours toes are not badly crushed :-(

Re: pcmanfm - How to set the preferred order of "open with" ?
Jim,

Quoted text here. Click to load it

I can actually understand the assumption itself.   Windows 95 is almost a  
quarter of a decade old.   Kids, and even adults might well have no idea of  
the existence of a CLI (under Windows or otherwise).  But as fate will have  
it, I do, and have used it quite a bit.

Quoted text here. Click to load it

Luckily the assumption missed me completely, so no damage done.  Doesn't  
mean that whomever dropped it should not be a bit more carefull though.  :-)

Regards,
Rudy Wieser



Re: pcmanfm - How to set the preferred order of "open with" ?
On Wed, 13 Nov 2019 12:22:14 +0100

Quoted text here. Click to load it

    My workaround is to use a very simple window manager and do most
things through the command line - but then I'm (very) old school unix.

--  
Steve O'Hara-Smith                          |   Directable Mirror Arrays
C:\>WIN                                     | A better way to focus the sun
We've slightly trimmed the long signature. Click to see the full one.
Re: pcmanfm - How to set the preferred order of "open with" ?
On Tue, 12 Nov 2019 09:28:15 -0500, Dennis Lee Bieber

Quoted text here. Click to load it

    Whatever it is, it is different from the behavior of Debian under xfce
(my VirtualBox image). Under xfce the right-click menu shows the default
opener, and the open-with submenu has a section of "recommended"
applications, followed by a listing of all applications on the system.

    In experimenting, I managed to locate (this is Debian)
-=-=-
wulfraed@debian:~$ cat ~/.config/mimeapps.list  
[Added Associations]
text/html=firefox-esr.desktop;
text/plain=mousepad.desktop;
text/x-python=python3.7.desktop;gvim.desktop;code.desktop;
x-scheme-handler/http=exo-web-browser.desktop
x-scheme-handler/https=exo-web-browser.desktop
x-scheme-handler/mailto=exo-mail-reader.desktop
application/xml=gvim.desktop;
text/x-scheme=gvim.desktop;
application/vnd.kde.kxmlguirc=gvim.desktop;

[Default Applications]
text/x-python3=gvim.desktop
text/x-python=gvim.desktop
wulfraed@debian:~$  
-=-=-

(and on Raspbian)
-=-=-
pi@rpi3bplus-1:~/.config$ cat ~/.config/mimeapps.list
[Default Applications]
text/x-python3=Thonny.desktop
text/x-python=Thonny.desktop
text/plain=gvim.desktop

[Added Associations]
text/x-python3=Thonny.desktop;gvim.desktop;userapp-python3.7-9AM0A0.desktop;
text/x-python=Thonny.desktop;gvim.desktop;
text/plain=gvim.desktop;
pi@rpi3bplus-1:~/.config$
-=-=-

    Which leads (Google) to
https://wiki.archlinux.org/index.php/XDG_MIME_Applications#mimeapps.list

    Hand editing the mimeapps.list files might be faster than piecemeal
"set default" applications. Also, the "set default" action is per user (the
above sample files), but you could edit a global file.

NOTE: Debian/Raspbian appears to use /usr/share/applications/mimeinfo.cache

... and editing  
pi@rpi3bplus-1:~$ sudo vim /usr/share/applications/mimeinfo.cache  

did NOT adjust the menu order... only the ~/.config/mimeapps.list seemed to
affect the ordering.


--  
    Wulfraed                 Dennis Lee Bieber         AF6VN
     snipped-for-privacy@ix.netcom.com    http://wlfraed.microdiversity.freeddns.org/

Re: pcmanfm - How to set the preferred order of "open with" ?
Dennis,

Quoted text here. Click to load it

I do have a mimeapps.list, though its located in  
/usr/share/raspi-ui-overrides-applications.  But checking its "last  
modified" date it shows way before the NOOBs package was installed on my Pi  
(which is two weeks ago).  Same for the "mimeinfo.cache" file next to it.  
In other words, they seem to be default/unaltered.

Also, no "[Added Associations]" in the first.

I've found a few of the above (looked like a good keyphrase), but only in  
the /usr/lib subfolders.

It looks like that idea (finding either de list of current defaults or the  
changes one) died fast ...

And odd: I did a grep -r "text/x-python3" on the /usr/share folder, but  
although I've set my .py files to open with "Text editor", all I can find is  
the mimetype coupled to "Thonny.desktop" and "applications-thonny.desktop"  
...

Regards,
Rudy Wieser



Re: pcmanfm - How to set the preferred order of "open with" ?
declaimed the following:

Quoted text here. Click to load it

    Note that .config is normally a hidden directory -- the period is
critical if using a shell/console.

Quoted text here. Click to load it

    Try your home directory (or do it with "sudo" on the filesystem root /
directory; sudo to minimize warnings about no privilege on some files)


--  
    Wulfraed                 Dennis Lee Bieber         AF6VN
     snipped-for-privacy@ix.netcom.com    http://wlfraed.microdiversity.freeddns.org/

Site Timeline