You are not logged in.

#26 2010-02-24 07:07:31

tzervo
Member
From: Athens
Registered: 2009-04-03
Posts: 86

Re: mimeo: open files by mimetype or file name

Removng the quotes allowed the "$@" part to work correctly, thanks! As for the "extension" thing, I dont know if it should be done, I was just skimming through /etc/mime.types and the documentation of xdg-mime and wondered if it can be done. I will read more on freedesktop and post again if I find anything of value.

Offline

#27 2010-02-27 23:44:52

tzervo
Member
From: Athens
Registered: 2009-04-03
Posts: 86

Re: mimeo: open files by mimetype or file name

One more question: does mimeo take into account the "Terminal=true" lines in the .desktop files? If yes, I am missing something (I have put one such line in my mplayer.desktop file and it doesn't work, it just dumps the output on the terminal I'm calling mimeo from). If not, it would be a very useful feature!! Btw grouping the files for opening by type is _great_!

Offline

#28 2010-02-28 08:52:24

Xyne
Administrator/PM
Registered: 2008-08-03
Posts: 6,965
Website

Re: mimeo: open files by mimetype or file name

It should work with "Terminal=true" now, although I haven't tested it beyond checking the output with "-c". I've added an option to specify the terminal to use, which defaults to "sh".

I've also added support for associations based on regex matching, which makes it possible to open URLs with mimeo or even open files by extension rather than mimetype. See "--help" and "--assoc-help" for more info. Just ask if anything isn't clear and I'll try to improve the documentation.

Let me know if it works.


My Arch Linux StuffForum EtiquetteCommunity Ethos - Arch is not for everyone

Offline

#29 2010-02-28 13:00:32

tzervo
Member
From: Athens
Registered: 2009-04-03
Posts: 86

Re: mimeo: open files by mimetype or file name

It is almost perfect! Both extension and terminal support work. A few ideas:

1) In conjunction with mimeman, when I associate a mime type with an already known app (an example: mplayer with file
/usr/share/applications/mplayer.desktop) mimeman does not create a new .desktop to my $HOME/.local/share/applications folder. However, mimeo does not recognize the already existent "global" mplayer.desktop. Also, a typo on the error message it spawns:

'is does not exist' --> 'does not exist'

2) I think it is preferable to take as a default terminal application the env. variable $TERMINAL and then fallback to /bin/sh as do some other openers, I think it is more robust.

3) Probably post a warning in the documentation about security issues when someone opens a file by extension? (I know, I asked for it knowing the danger but someone else might not want to take the risk  :-) )

Also, reminder to myself:
Go learn python so I will be able to fix and then report back instead of pestering Xyne!! :-)

EDIT

Also, line 243, these "failed" messages keep being printed whenever one opens a file (I understand it is every time mimeo makes a test against the "extension open" file). If I try to open, say, 15 files and I have declared 3 extensions, the message is printed on my terminal 45 times!!

Last edited by tzervo (2010-02-28 20:55:52)

Offline

#30 2010-02-28 21:40:16

Xyne
Administrator/PM
Registered: 2008-08-03
Posts: 6,965
Website

Re: mimeo: open files by mimetype or file name

1) Can you please give more information? What commands are you using, what do you expect to happen and what actually happens? Also check that you're associating the correct mimetype by checking the reported mimetype with "mimeo -m <path>".

I've fixed the "is does" typo.

2) How would I determine the option to run a command? Some use "-c" (e.g. "sh"), some use "-e" (e.g. urxvt), and others might use something else. Is there some universal way to detect that?

3) There is no more danger in opening by extension then opening by mimetype as the user can configure both manually. Any warning would apply to mimeo in general and not just to using the associations file, but I wonder if that's really necessary and I don't even know where I would put it. (In the help text?) If I write a man page then I could mention it there, but right now it would feel like writing "caution: contents are cold" on the freezer door.


I've removed the "failed" message. It was a leftover test statement. Sorry about that.


My Arch Linux StuffForum EtiquetteCommunity Ethos - Arch is not for everyone

Offline

#31 2010-03-01 18:09:11

tzervo
Member
From: Athens
Registered: 2009-04-03
Posts: 86

Re: mimeo: open files by mimetype or file name

1) Forget it, I started tracing what I executed but on the way I noticed that what I did had no purpose. My mistake!
2) Other mime openers (e.g. mimeopen) use the $TERMINAL variable (which can be set to "/bin/sh -c" or  "xterm -e" etc.) but here as well probably there is no gain so, again ignore my comment!
3) You're right, I had not thought about it   :-) .

EDIT

Concerning point 1) again
Executing:

 mimeman --assoc --mimetype "application/x-flac" --app "mplayer"

and then

 mimeo something.flac

gives

 error: /home/tzervo/dotfiles/.local/share/applications/mplayer.desktop does not exist or is not a file

The file /usr/share/applications/mplayer.desktop exists, and I assume that mimeman locates it and does not make a new $HOME/.local/share/applications/mplayer.desktop file. My relevant entry that is created by mimeman in my LOCAL mimeinfo.cache is

 application/x-flac=mplayer.desktop

mimeo -m gives the mimetype as "application/x-flac". Of course, copying the global file to the $HOME/.../applications folder solves the problem, but I assume that you wanted mimeo to also look in the global /usr/share/applications in the first place?

Last edited by tzervo (2010-03-01 19:40:27)

Offline

#32 2010-03-02 01:48:22

Xyne
Administrator/PM
Registered: 2008-08-03
Posts: 6,965
Website

Re: mimeo: open files by mimetype or file name

I can't reproduce this. I installed mplayer and associated mp3 files with it using mimeman and "prefer" to make sure that it would take precedence over previous associations. Mimeo correctly used the mplayer.desktop file in /usr/share/applications.


Post the following files and I will try to debug this:

~/.local/share/applications/defaults.list
~/.local/share/applications/mimeinfo.cache
/usr/share/applications/mplayer.desktop

You can also try running "mimeman --purge" and check that the mplayer.desktop file exists and is readable.


My Arch Linux StuffForum EtiquetteCommunity Ethos - Arch is not for everyone

Offline

#33 2010-03-02 03:32:49

tzervo
Member
From: Athens
Registered: 2009-04-03
Posts: 86

Re: mimeo: open files by mimetype or file name

I didn't do the "--prefer" step so I didn't have the "defaults.list" file in .local/share/applications (mimeo/mimeman worked for all the other cases since they created *-usercreated-0.desktop files there which apparenty were located and used even if I only used mimeman's --assoc flag with them). False alarm again, sorry!

Offline

#34 2010-03-02 06:01:19

Xyne
Administrator/PM
Registered: 2008-08-03
Posts: 6,965
Website

Re: mimeo: open files by mimetype or file name

It should work without a defaults.list file, using only "--assoc". When no default is found, it uses the first association that it finds.

Let me know if you find a way to reliably reproduce the error (I'm not asking you to look for one, but if you happen to find it, I would be interested).


My Arch Linux StuffForum EtiquetteCommunity Ethos - Arch is not for everyone

Offline

#35 2010-03-02 21:06:55

tzervo
Member
From: Athens
Registered: 2009-04-03
Posts: 86

Re: mimeo: open files by mimetype or file name

I executed the following steps exactly:

1) backup $HOME/.local/share/applications folder and then rm -rf $HOME/.local/share/applications so that I make a clean start (to be sure).
2) execute

mimeman --assoc --mimetype "audio/mpeg" --app "mplayer"

At this point the only file in $HOME/.local/share/applications is the mimeinfo.cache file with contents:

[MIME Cache]
audio/mpeg=mplayer.desktop

Of course, the "global" /usr/share/applications/mplayer.desktop exists.

3) mimeo something.mp3. It gives the error:

error: /home/tzervo/dotfiles/.local/share/applications/mplayer.desktop does not exist or is not a file

Since the global /usr/share/applications/mplayer.desktop exists I assume it is not parsed.

4) execute

cp /usr/share/applications/mplayer.desktop ~/.local/share/applications

5) mimeo something.mp3 now executes correctly.

Clarification: I did not --prefer anything with mimeman so maybe this is where my steps differ from yours. I can't think of anything else. Feel free to propose anything that comes to your mind and I will try it.

EDIT: On line 134 of mimeo if I change "dpath = mimeinfo[mimetype][0]" to "dpath = mimeinfo[mimetype][1]", step 3 works! I don't know python, I just fiddled with it intuitively. In fact, changing lines 131-141 with the following:

    if defaults.has_key(mimetype):
      dpath = defaults[mimetype]
    elif mimeinfo.has_key(mimetype):
      dpath0 = mimeinfo[mimetype][0]
      dpath1 = mimeinfo[mimetype][1]
      if os.path.isfile(dpath0):
         dpath = dpath0
      elif os.path.isfile(dpath1):
         dpath = dpath1
      else:
         print "error: %s does not exist or is not a file" % dpath
         exit(1)
    else:
      print "error:", mimetype
      exit(1)

works for me!  :-)

Last edited by tzervo (2010-03-02 21:37:13)

Offline

#36 2010-03-03 01:14:20

Xyne
Administrator/PM
Registered: 2008-08-03
Posts: 6,965
Website

Re: mimeo: open files by mimetype or file name

Ok, it should be fixed now. Thanks for the feedback.

The problem wasn't actually in that section of code but rather and earlier section where I load the application associations. The code blindly assumed that mimeinfo.cache files only referred to desktop files in the same directory and that they must exist.


My Arch Linux StuffForum EtiquetteCommunity Ethos - Arch is not for everyone

Offline

#37 2010-03-03 06:53:42

tzervo
Member
From: Athens
Registered: 2009-04-03
Posts: 86

Re: mimeo: open files by mimetype or file name

Glad I could help!  :-)

Offline

#38 2010-03-03 08:04:44

tzervo
Member
From: Athens
Registered: 2009-04-03
Posts: 86

Re: mimeo: open files by mimetype or file name

I think it stopped parsing /usr/share/aplications/mimeinfo.cache. Trying to open a pdf gives:
error: application/pdf
if it is not declared in .local/share/applications/mimeinfo.cache
Previously it functioned ok. Also, there is a leftover print message whenever it opens a file.

Offline

#39 2010-03-03 10:14:23

Xyne
Administrator/PM
Registered: 2008-08-03
Posts: 6,965
Website

Re: mimeo: open files by mimetype or file name

Fixed  and fixed.

Python -> significant whitespace + indentation error = broken loop


My Arch Linux StuffForum EtiquetteCommunity Ethos - Arch is not for everyone

Offline

#40 2011-02-17 23:26:08

Hoek
Member
Registered: 2010-08-27
Posts: 7

Re: mimeo: open files by mimetype or file name

Sorry to dig out this thread again, but i'm trying to find a mime opener that works, at last, and Xyne's mimeo seems very promising.

However, i can't seem to get any mime association tool (tried mimeman and mimeopen) to associate inkscape to image/svg+xml.

When using mimeo:

> mimeman --mimetype 'image/svg+xml' --prefer 'inkscape' --name 'Inkscape'
> mimeo file.svg
> error: invalid executable: ooffice

WTF? ooffice is long gone and wiped in favor of libreoffice...

> mimeman --purge
> mimeman --dissoc --app 'ooffice' --mimetype 'image/svg+xml'
> mimeo file.svg
(opening file.svg in geeqie)

Ok, guess geeqie has a preference as image viewer.. (Disabling geeqie's svg association in its prefs)

> mimeman --mimetype 'image/svg+xml' --assoc 'inkscape' --name 'Inkscape'
> mimeo file.svg
> error: invalid executable: ooffice

Ok, this is ridiculous.

Let's try mimeopen:

> mimeopen file.svg
Please choose a default application for files of type image/svg+xml

        1) winebrowser  (wine-extension-xml)
        2) Opera  (opera-browser)
        3) Other...

use application #

Choose 3, type in 'inkscape'. It opens in inkscape, yay!

> mimeopen file.svg
Please choose a default application for files of type image/svg+xml

        1) winebrowser  (wine-extension-xml)
        2) Opera  (opera-browser)
        3) Other...

use application #

WTF, you didn't remember it..?!
Let's see what xdg-mime thinks of it:

> xdg-mime query default image/svg+xml
inkscape-usercreated-1.desktop

> cat ~/.local/share/applications/inkscape-usercreated-1.desktop 
[Desktop Entry]
Version=1.0
Encoding=UTF-8
Type=Application
Name=inkscape
NoDsiplay=true
Exec=inkscape

Ok, let's see our defaults.list:

> cat ~/.local/share/applications/defaults.list
[Default Applications]
application/pdf=epdfview.desktop
audio/mpeg=audacious2.desktop
image/jpeg=gqview-usercreated-1.desktop
image/png=geeqie.desktop
image/svg+xml-compressed=inkscape.desktop
text/x-tex=vim-usercreated-1.desktop
video/x-flv=mplayer.desktop
image/svg+xml=inkscape-usercreated-1.desktop;

So everything seems normal. Nowhere is the mysterious oowriter to be found, and yet, still, no way to automatically open .svg or .svgz files with inkscape, though all mime openers recognize the svg file as image/svg+xml.

I'm giving up here. Any advice?

Last edited by Hoek (2011-02-17 23:27:37)

Offline

#41 2011-02-19 05:23:09

Xyne
Administrator/PM
Registered: 2008-08-03
Posts: 6,965
Website

Re: mimeo: open files by mimetype or file name

Hoek wrote:

I'm giving up here. Any advice?

$ mimeo -c SVG-logo.svg 
/usr/bin/mirage SVG-logo.svg

$ mimeman --mimetype 'image/svg+xml' --prefer --app 'inkscape'

$ mimeo -c SVG-logo.svg 
/usr/bin/inkscape SVG-logo.svg

smile


EDIT:
Using "--name" should work. I'll take a look at the code to check for bugs. I haven't touched mimeman in a while and I intend to eventually rewrite it in Python to match mimeo.

Last edited by Xyne (2011-02-19 05:26:53)


My Arch Linux StuffForum EtiquetteCommunity Ethos - Arch is not for everyone

Offline

#42 2011-02-19 14:54:55

Hoek
Member
Registered: 2010-08-27
Posts: 7

Re: mimeo: open files by mimetype or file name

Hey Xyne, thank you very much. That helped, of course. smile

Offline

#43 2011-02-22 08:57:05

Xyne
Administrator/PM
Registered: 2008-08-03
Posts: 6,965
Website

Re: mimeo: open files by mimetype or file name

I've now transferred most of Mimeman's functionality to Mimeo and made many improvesments along the way. Mimeo can now manage MIME-type associations and should be (mostly) standards-compliant.

See "mimeo --help" for the new options, and remove the kludge that was mimeman.


My Arch Linux StuffForum EtiquetteCommunity Ethos - Arch is not for everyone

Offline

#44 2011-02-22 12:59:42

Dieter@be
Forum Fellow
From: Belgium
Registered: 2006-11-05
Posts: 2,001
Website

Re: mimeo: open files by mimetype or file name

Xyne wrote:

(well, I don't actually use it, but if I did use an opener, this would be it) and I share it in case someone else finds it useful. If you know of a better app, use it. smile

so, which opener do you use?


< Daenyth> and he works prolifically
4 8 15 16 23 42

Offline

#45 2011-02-22 13:59:24

Xyne
Administrator/PM
Registered: 2008-08-03
Posts: 6,965
Website

Re: mimeo: open files by mimetype or file name

Dieter@be wrote:

so, which opener do you use?

urxvt and gmrun tongue

With the recent updates though, I'll be using mimeo more often, especially to manage associations.


My Arch Linux StuffForum EtiquetteCommunity Ethos - Arch is not for everyone

Offline

#46 2011-02-26 20:53:48

demonicmaniac
Member
Registered: 2009-01-20
Posts: 9

Re: mimeo: open files by mimetype or file name

Thank you so much!
mimeo and mimeman really are a godsend, you are the man!

Offline

#47 2011-02-26 22:02:46

Xyne
Administrator/PM
Registered: 2008-08-03
Posts: 6,965
Website

Re: mimeo: open files by mimetype or file name

@demonicmaniac
Thanks!

Btw, mimeman is deprecated. You should be able to use mimeo to do everything that mimeman used to do.


My Arch Linux StuffForum EtiquetteCommunity Ethos - Arch is not for everyone

Offline

#48 2011-02-26 22:11:00

demonicmaniac
Member
Registered: 2009-01-20
Posts: 9

Re: mimeo: open files by mimetype or file name

Heh ya, silly me. I read the mimeman deprecation just after i'd sent you my love for both smile
Truth be told, i touched mimeman once to set all default apps and that was it heh.

Offline

#49 2011-02-27 07:34:19

Ledti
Member
Registered: 2010-07-31
Posts: 122
Website

Re: mimeo: open files by mimetype or file name

Hi Xyne, I noticed that the mimeman functionality of mimeo won't work if there is no $HOME/.local/applications folder. I remember mimeman would create this folder automatically, so I don't know if this is intentional or not.

It might also be a good idea to add the mime-types package (are there any others?) to the optdepends array in the mimeo package. I noticed there weren't many mimetypes being added after forgetting mime-types wasn't installed.

Thanks for mimeo (and your many other contributions). smile

Offline

#50 2011-03-02 18:01:08

Xyne
Administrator/PM
Registered: 2008-08-03
Posts: 6,965
Website

Re: mimeo: open files by mimetype or file name

@Ledti
Sorry, I somehow missed your post.

Mimeo should now create missing directories when updating files. Let me know if I missed a case (along with the command).


I've also added "mime-types" to the optdepends.


My Arch Linux StuffForum EtiquetteCommunity Ethos - Arch is not for everyone

Offline

Board footer

Powered by FluxBB