You are not logged in.

#76 2012-02-28 02:17:12

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

Re: mimeo: open files by mimetype or file name

Yeah, that's clear... I just don't know what the best solution is. I did some research before switching my hashbangs over to use env, and it seemed that the consensus was that using env was the best compromise on most systems. I'm not opposed to reverting to direct paths but I need to research it again.

Can you just create a mimeo clone with #!/usr/bin/python2 in the meantime?


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

Offline

#77 2012-02-28 17:03:15

dakra
Member
Registered: 2012-02-13
Posts: 3

Re: mimeo: open files by mimetype or file name

Is mimeo arch specific? If so, what's wrong with making it the direct python2 path?
If it's not arch specific and you want it for more systems then you have to use the packaging system to change that line for you.
E.g. if you want to distribute it as an egg (on pypi, etc), then you most likely will have somethin like this in your setup.py:
---
entry_points = dict(
          console_scripts = [
              "mimeo = Mimeo:main"
          ],
      ),
---
then setuptools/distribute will generate the /usr/bin/mimeo file (with a fix python interpreter) for you.

Hope that helps,
  Daniel

PS: Of course I just changed the header 'by hand', but thought it might help to fix it in the upstream.

Offline

#78 2012-09-02 16:09:42

shugoshin
Member
Registered: 2012-08-18
Posts: 8

Re: mimeo: open files by mimetype or file name

Hi Xyne,

first of all thank you for making mimeo available.

I couldn't find a solution to my problem yet I would really appreciate your help.

I use a tcl script program named A Plasmid Editor (http://biologylabs.utah.edu/jorgensen/wayned/ape/)  with tclklik to open/edit essentially text/plain mime-type files that have extensions .ape .dna etc. I have created an ape.desktop file which executes " tclkit /path/to/script/ApE.tcl". In pcmanfm I can right click and choose this "program" to open such files with ApE, however,

1) I would like to be able to open them with double click of the icon in pcmanfm
2) also be able to open them using the "file:///path/to/ape_file.dna" links in libreoffice documents.

I am not sure if the solution to 1 and 2 are the same. At least for the first part I tried change the tclkit.desktop "Exec=" line from "tclkit %f" to "tclkit  /path/to/script/ApE.tcl" (anyway this is the only tcl script currently I am using) and I put the following lines to ~/.config/mimeo.conf:

   /usr/bin/tclkit
     \.dna$
     \.ape$

"$ mimeo ape_file.dna " command still opens the file in leafpad.

I hope you will be able to direct to a solution.

Thanks in advance,

Offline

#79 2012-09-02 17:44:27

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

Re: mimeo: open files by mimetype or file name

Hi,

shugoshin wrote:

At least for the first part I tried change the tclkit.desktop "Exec=" line from "tclkit %f" to "tclkit  /path/to/script/ApE.tcl"

Why did you omit "%f" from the new command? That's the placeholder for the file name. Normally the filename will be added to the end of the command if no placeholder is found, but I would keep it if the original Exec line included it.

In any case, editing the desktop file is not the way to do this. It will be overwritten on update and break any application that uses it (which is probably none, but it's bad practice nevertheless).  You can create custom desktop files with mimeo (see below), or you can just copy the tcl desktop file to ~/.local/share/applications, rename it and edit it as you wish.

shugoshin wrote:

and I put the following lines to ~/.config/mimeo.conf:

/usr/bin/tclkit 
  \.dna$
  \.ape$

The syntax is correct but I would also add "%f" or "%F" to the command in mimeo.conf. You have also omitted "/path/to/script/ApE.tcl" from the command. Nevertheless, it should try to open those files with tclkit. If it is still opening them with leafpad then you have misconfigured something.

I would include the following in mimeo.conf:

/usr/bin/tclkit /path/to/script/ApE.tcl %f
  \.dna$
  \.ape$

It yields the expected results:

$ mimeo -c ape_file.dna
/usr/bin/tclkit /path/to/script/ApE.tcl ape_file.dna

Make sure that there are no syntax errors mimeo.conf and that the file is readable by the user running mimeo. If you are using sudo or any other command that changes the effective user ID then you need to edit that user's mimeo.conf.

Check the command that mimeo is trying to use by passing it the "-c" option, as shown in the example above. If you do not get the same output that I did for the same configuration file then you have done something wrong.

I would also check what mimetype mimeo reports for .dna and .ape files, as it may be different than the type reported by some other commands.

mimeo -m ape_file.dna

If it is unique(-ish), then create a custom desktop with mimeo and associate it with that mimetype

mimeo --create ape.desktop APE '/usr/bin/tclkit /path/to/script/ApE.tcl %f' mime/type
mimeo --prefer mime/type ape.desktop

After that you could either create a preference for that desktop file directly in pcmanfm if it detects the same mimetype, or you could create a preference for mimeo if it detects something else. You could also remove the above lines from mimeo.conf if the mimetype is unique.

If the mimetype truly is text/plain then use the mimeo.conf posted above and configure pcmanfm to open .ape and .dna files with mimeo. Do not use mimeo to set a preference for mimeo. This will likely create an infinite loop or invoke the end of days. Mimeo will catch .ape and .dna files by name and pass other text/plain types to your preferred text editor.

Finally, for libreoffice, regardless of the method used above, you should just need to specify mimeo as the file opener for those documents.

I hope this helps.


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

Offline

#80 2012-10-24 11:12:44

jakob
Member
From: Berlin
Registered: 2005-10-27
Posts: 419

Re: mimeo: open files by mimetype or file name

Hey,

thanks for this nice contribution, Xyne! However, I'm not quite sure whether this is useful to me: I'm mainly concerned with links clicked in libreoffice not to open in chromium. However, I wasn't able to achieve this with mimeo. I also didn't get 'mimeo http://www.example.com' to open in another browser than chromium, also I run '--clear' '--purge' '--unprefer' chromium.desktop several times and '--prefer dwb.desktop' -> no avail. Only setting it in ~/.config/mimeo.conf as file-assoc helped.

But then, how do I make other programmes such as libreoffice use mimeo, i.e. how do I set mimeo to be the default handler for associations? Because libreoffice still opened links with chromium.

Only setting x-scheme-handler/http to dwb.desktop in xdg-mime proved successful, so I wonder whether xdg-utils have become better or whether I just wasn't using mimeo correctly?

Best, Jakob

Offline

#81 2012-10-24 11:27:15

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

Re: mimeo: open files by mimetype or file name

@jakob
The '--prefer' option requires a MIME-type matcher. See 'mimeo --mimeman-help' for the syntax. You need to tell it exactly which MIME-types to preferentially associate with dwb. You can also check the detected MIME-type of a file with 'mimeo -m <filepath>'.

The problem in your case is that a URL is not a file, so there is no MIME-type. This is exactly what the configuration file is for. If you want to open arbitrary strings and commands, you need to include them in that file. There are not hard-coded types in mimeo, so when you pass it a URL, all it sees is a string that it compares against patterns in the configuration file. If nothing matches then it checks for a file of the same name to get a MIME-type. If there is no file then it fails.

As for setting mimeo as the default opening in e.g. libreoffice, I have no idea as generally do not use it. Each application will have its own preference manager, e.g. my email client has been configured to use mimeo.

Maybe xdg-utils-mimeo would help. I have never used it myself so I do not know.


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

Offline

#82 2012-10-24 12:10:42

jakob
Member
From: Berlin
Registered: 2005-10-27
Posts: 419

Re: mimeo: open files by mimetype or file name

Wow, that was a quick answer, thx alot for that! Due to procrastination reasons, I'll reply equally fast smile

Xyne wrote:

@jakob
The '--prefer' option requires a MIME-type matcher. See 'mimeo --mimeman-help' for the syntax. You need to tell it exactly which MIME-types to preferentially associate with dwb. You can also check the detected MIME-type of a file with 'mimeo -m <filepath>'.

The problem in your case is that a URL is not a file, so there is no MIME-type. This is exactly what the configuration file is for. If you want to open arbitrary strings and commands, you need to include them in that file. There are not hard-coded types in mimeo, so when you pass it a URL, all it sees is a string that it compares against patterns in the configuration file. If nothing matches then it checks for a file of the same name to get a MIME-type. If there is no file then it fails.

I see, that explains why I needed mimeo.conf. I was deceived by mimeo's readiness to output something to 'mimeo -d http://' and thought that I could use http:// as a proper MIME-type, so a clear misunderstanding on my part.

Xyne wrote:

As for setting mimeo as the default opening in e.g. libreoffice, I have no idea as generally do not use it. Each application will have its own preference manager, e.g. my email client has been configured to use mimeo.

Maybe xdg-utils-mimeo would help. I have never used it myself so I do not know.

Hm, I think it is easier then to stick to xdg-open, since it is more standard, upstream-maintained and additionally, xdg-utils-mimeo (according to AUR comments) doesn't seem to compile anymore.

But thanks still for that nice utilty!

Offline

#83 2012-12-20 09:16:53

ngoonee
Forum Fellow
From: Between Thailand and Singapore
Registered: 2009-03-17
Posts: 7,358

Re: mimeo: open files by mimetype or file name

Hi Xyne, been using mimeo with xdg-utils-mimeo for a while now and just now running into a bit of a fix as I'm spending more time in ranger than nautilus.

Xournal files have extension .xoj but their mimetype is application/x-gzip. Any way to match xournal.desktop to files of extension xoj rather than all x-gzip files (which would of course include all my *.gz files which I don't want xournal to be default for)?


Allan-Volunteer on the (topic being discussed) mailn lists. You never get the people who matters attention on the forums.
jasonwryan-Installing Arch is a measure of your literacy. Maintaining Arch is a measure of your diligence. Contributing to Arch is a measure of your competence.
Griemak-Bleeding edge, not bleeding flat. Edge denotes falls will occur from time to time. Bring your own parachute.

Offline

#84 2012-12-21 15:57:55

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

Re: mimeo: open files by mimetype or file name

You could use the associations file:

$XDG_CONFIG_HOME/mimeo.conf

/usr/bin/xournal %f
  \.xoj$

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

Offline

#85 2012-12-23 23:22:49

ngoonee
Forum Fellow
From: Between Thailand and Singapore
Registered: 2009-03-17
Posts: 7,358

Re: mimeo: open files by mimetype or file name

Thanks! I refused to believe there wasn't documentation on this, so I read and reread mimeo -h and finally found mimeo --assoc-help smile


Allan-Volunteer on the (topic being discussed) mailn lists. You never get the people who matters attention on the forums.
jasonwryan-Installing Arch is a measure of your literacy. Maintaining Arch is a measure of your diligence. Contributing to Arch is a measure of your competence.
Griemak-Bleeding edge, not bleeding flat. Edge denotes falls will occur from time to time. Bring your own parachute.

Offline

#86 2012-12-24 00:28:47

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

Re: mimeo: open files by mimetype or file name

ngoonee wrote:

Thanks! I refused to believe there wasn't documentation on this, so I read and reread mimeo -h and finally found mimeo --assoc-help smile

Yeah, I probably need to make this functionality more visible. I suspect the other openers floating around were written because they did not realize that mimeo could do this.


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

Offline

#87 2013-02-13 01:57:07

ngoonee
Forum Fellow
From: Between Thailand and Singapore
Registered: 2009-03-17
Posts: 7,358

Re: mimeo: open files by mimetype or file name

% mimeo
warning: environment variable "XDG_DATA_DIRS" is not setwarning: environment variable "XDG_CONFIG_DIRS" is not set

Never remember having to explicitly set these, has something changed?

EDIT: Yes it has... with libx11 - https://bugs.archlinux.org/task/31204

EDIT2: 'normal' xdg-utils still works, so I'm not sure whether mimeo needs some form of an update.

Last edited by ngoonee (2013-02-13 02:20:59)


Allan-Volunteer on the (topic being discussed) mailn lists. You never get the people who matters attention on the forums.
jasonwryan-Installing Arch is a measure of your literacy. Maintaining Arch is a measure of your diligence. Contributing to Arch is a measure of your competence.
Griemak-Bleeding edge, not bleeding flat. Edge denotes falls will occur from time to time. Bring your own parachute.

Offline

#88 2013-02-13 04:46:54

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

Re: mimeo: open files by mimetype or file name

When I updated earlier today I didn't both changing the system directories as someone mentioned that only the default user directories were dropped.

Updated again.

Was there any warning before/during the package upgrade that dropped those variables? Surely this could cause some damage if users are relying on those variables for various scripts and apps.


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

Offline

#89 2013-02-13 04:52:57

ngoonee
Forum Fellow
From: Between Thailand and Singapore
Registered: 2009-03-17
Posts: 7,358

Re: mimeo: open files by mimetype or file name

Nope, no warning at all. Update works, thanks. Still getting the warning: environment variable "XDG_CONFIG_DIRS" is not set though.


Allan-Volunteer on the (topic being discussed) mailn lists. You never get the people who matters attention on the forums.
jasonwryan-Installing Arch is a measure of your literacy. Maintaining Arch is a measure of your diligence. Contributing to Arch is a measure of your competence.
Griemak-Bleeding edge, not bleeding flat. Edge denotes falls will occur from time to time. Bring your own parachute.

Offline

#90 2013-02-13 05:17:24

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

Re: mimeo: open files by mimetype or file name

  elif var == 'XDG_DATA_DIRS':
    return xdg_data_dirs
  elif var == 'XDG_DATA_DIRS':
    return xdg_config_dirs

copy+paste-edit=fail

oops, fixed, uploading


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

Offline

#91 2013-02-13 05:47:47

ngoonee
Forum Fellow
From: Between Thailand and Singapore
Registered: 2009-03-17
Posts: 7,358

Re: mimeo: open files by mimetype or file name

This one is fine, thanks smile


Allan-Volunteer on the (topic being discussed) mailn lists. You never get the people who matters attention on the forums.
jasonwryan-Installing Arch is a measure of your literacy. Maintaining Arch is a measure of your diligence. Contributing to Arch is a measure of your competence.
Griemak-Bleeding edge, not bleeding flat. Edge denotes falls will occur from time to time. Bring your own parachute.

Offline

#92 2013-07-24 17:35:09

Ram-Z
Member
Registered: 2012-09-04
Posts: 18

Re: mimeo: open files by mimetype or file name

Hay Xyne,

There seems to be an issue with Exec lines containing either %i or %c. gwenview.desktop for example contains:

Exec=gwenview %U -caption "%c" %i

but:

% mimeo -c image.png
gwenview image.png -caption Gwenview '' --icon gwenview ''

all those single quotes mess up the command.

Thanks for this great tool.

Offline

#93 2013-07-24 20:52:19

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

Re: mimeo: open files by mimetype or file name

@Ram-Z
It should work now:

> mimeo -c ./foo.png 
gwenview ./foo.png -caption Gwenview --icon gwenview

Let me know if I have broken anything else in the process.


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

Offline

#94 2013-07-24 21:07:39

Ram-Z
Member
Registered: 2012-09-04
Posts: 18

Re: mimeo: open files by mimetype or file name

Works like a charm, thx.

BTW: I have uploaded mimeo to Chakra's CCR: http://chakra-linux.org/ccr/packages.php?ID=5620

Offline

#95 2013-07-24 21:11:02

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

Re: mimeo: open files by mimetype or file name

Ram-Z wrote:

BTW: I have uploaded mimeo to Chakra's CCR: http://chakra-linux.org/ccr/packages.php?ID=5620

Thanks. It's nice to see my stuff get used.


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

Offline

#96 2013-08-25 10:12:24

Ram-Z
Member
Registered: 2012-09-04
Posts: 18

Re: mimeo: open files by mimetype or file name

This doesn't seem to work:

$ cat ~/.config/mimeo.conf
/usr/bin/mplayer "$(youtube-dl -g %u)"
   ^https?://www.youtube.com/watch\?(.*&)*v=.*
$ mimeo -c "https://www.youtube.com/watch?v=r_CmvO8Ajc0"
/usr/bin/mplayer '$(youtube-dl -g https://www.youtube.com/watch?v=r_CmvO8Ajc0)'
$ mimeo "https://www.youtube.com/watch?v=r_CmvO8Ajc0"
[..]
Playing $(youtube-dl -g https://www.youtube.com/watch?v=r_CmvO8Ajc0).
No stream found to handle url $(youtube-dl -g https://www.youtube.com/watch?v=r_CmvO8Ajc0)
[..]

An obvious and simple workaround would be to write and call a small sh script instead. So consider this more of a "let you know" than a "feature request".

Offline

#97 2013-08-25 10:51:29

progandy
Member
Registered: 2012-05-17
Posts: 5,266

Re: mimeo: open files by mimetype or file name

Ram-Z wrote:

An obvious and simple workaround would be to write and call a small sh script instead. So consider this more of a "let you know" than a "feature request".

You should use this command I think:

sh -c '/usr/bin/mplayer "$(youtube-dl -g "$1")"' m-ytdl "%u"

Last edited by progandy (2013-08-25 10:52:23)


| alias CUTF='LANG=en_XX.UTF-8@POSIX ' |

Offline

#98 2013-08-25 11:18:03

Ram-Z
Member
Registered: 2012-09-04
Posts: 18

Re: mimeo: open files by mimetype or file name

/usr/bin/mplayer "$(youtube-dl -g %u)" works just fine on its own. It's only when run within mimeo that $(youtube-dl [..]) isn't executed (probably because the double quotes are replaced by single quotes).

progandy wrote:

sh -c '/usr/bin/mplayer "$(youtube-dl -g "$1")"' m-ytdl "%u"

$ cat ~/.config/mimeo.conf
sh -c '/usr/bin/mplayer "$(youtube-dl -g "$1")"' m-ytdl "%u"
   ^https?://www.youtube.com/watch\?(.*&)*v=.*
$ mimeo -c "https://www.youtube.com/watch?v=r_CmvO8Ajc0"
sh -c ''"'"'/usr/bin/mplayer' '$(youtube-dl -g $1)'"'"'' m-ytdl 'https://www.youtube.com/watch?v=r_CmvO8Ajc0'

This has no chance of being executed correctly.

Offline

#99 2013-08-25 16:50:23

progandy
Member
Registered: 2012-05-17
Posts: 5,266

Re: mimeo: open files by mimetype or file name

Ram-Z wrote:

/usr/bin/mplayer "$(youtube-dl -g %u)" works just fine on its own. It's only when run within mimeo that $(youtube-dl [..]) isn't executed (probably because the double quotes are replaced by single quotes).

I forgot shlex.split doesn't like single quotes. Here is the proper command

>>>  from pprint import pprint
>>> import shlex
>>> s='sh -c "/usr/bin/mplayer \\"$(youtube-dl -g \\"$1\\")\\"" m-ytdl "%u"'
>>> print(s)   

### The following string should work in mimeo.conf
sh -c "/usr/bin/mplayer \"$(youtube-dl -g \"$1\")\"" m-ytdl "%u"


>>> pprint(shlex.split(s))
['sh', '-c', '/usr/bin/mplayer "$(youtube-dl -g "$1")"', 'm-ytdl', '%u']

Last edited by progandy (2013-08-25 16:53:37)


| alias CUTF='LANG=en_XX.UTF-8@POSIX ' |

Offline

#100 2013-08-25 20:22:31

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

Re: mimeo: open files by mimetype or file name

This works for me:

sh -c "/usr/bin/mplayer \"$(youtube-dl -g '%u')\""
  ^https?://www.youtube.com/watch\?(.*&)*v=.*

That's a nice idea for a custom command btw. wink


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

Offline

Board footer

Powered by FluxBB