Google Groups no longer supports new Usenet posts or subscriptions. Historical content remains viewable.
Dismiss

file associations

2 views
Skip to first unread message

jenea

unread,
Mar 12, 2005, 10:02:27 AM3/12/05
to
Hi!
how could I make so that if I type in command line
> file_name.mp3
an xmms will be opened playing that song ...
this is just an example....

the point it to make bash understand mime types , at least analysing
file extension....
i.e mp3 , mpeg ... for xmms
txt , cpp , c for kate
and so on .

10x in advance ;

Peter T. Breuer

unread,
Mar 12, 2005, 10:35:56 AM3/12/05
to
jenea <pui...@gmail.com> wrote:
> how could I make so that if I type in command line
> > file_name.mp3
> an xmms will be opened playing that song ...

Use a shell that does that.

> the point it to make bash understand mime types , at least analysing

No it isn't. Unless you want to rewrite it.

Peter

James McIninch

unread,
Mar 12, 2005, 11:07:51 AM3/12/05
to jenea
<posted & mailed>

Well, MIME types have nothing to do with the suffixes. If you want to map
file suffixes to mime-types, that would be one thing. Associating a type
with a preffered application, another thing.

The shell won't do this for you, but you can easily use the misc_binfmt
functionality to declare that all .mp3 files are executables to be opened
by XMMS. In that case, you simply mark them executable (chmod u+x) and then
type the filename at the shell prompt and XMMS will play the tune.

jenea wrote:

--
Remove '.nospam' from e-mail address to reply by e-mail

Reader

unread,
Mar 12, 2005, 1:50:44 PM3/12/05
to
On Sat, 12 Mar 2005 07:02:27 -0800, jenea wrote:

> how could I make so that if I type in command line
>> file_name.mp3
> an xmms will be opened playing that song ...
> this is just an example....

If you're running KDE, you could ask konqueror to handle it:
konqueror file_name.mp3

jenea

unread,
Mar 12, 2005, 3:58:38 PM3/12/05
to
I tried the following :
I edited /proc/sys/fs/binfmt_misc/register
with the following format
mp3:E::mp3::/usr/bin/xmms

but when i try to save it .... there is a message says that
"could not be saved"
I could not understand it , because I am logged as root!
also I chmod it:
>chmod +777 register
!!!
i tried vi , mcedit , emacs.... all of them says the same thing....
Any suggestion ?

10x in advance ;)

Joe Feise

unread,
Mar 12, 2005, 4:16:27 PM3/12/05
to
jenea wrote on 03/12/05 12:58:

> I tried the following :
> I edited /proc/sys/fs/binfmt_misc/register
> with the following format
> mp3:E::mp3::/usr/bin/xmms
>
> but when i try to save it .... there is a message says that
> "could not be saved"
> I could not understand it , because I am logged as root!


/proc is not a real filesystem. The kernel puts stuff there for you to see.

-Joe

jenea

unread,
Mar 13, 2005, 2:33:20 AM3/13/05
to
James says

"but you can easily use the misc_binfmt
functionality to declare that all .mp3 files are executables to be
opened
by XMMS"
If /proc is "not a real filesystem" , hence , I can't edit
/proc/sys/fs/misc_binfmt/register ...
How could I do that?
google in this case is useless :(
10x in advance.

Michael Heiming

unread,
Mar 13, 2005, 3:11:21 AM3/13/05
to
In alt.os.linux jenea <pui...@gmail.com>:

First of, never used binfmt_misc prior to your post.

There's not always a need to google, specially if the answer is
directly on your system, if you have (you should) installed the
kernel sources:

/usr/src/linux*/Documentation/binfmt_misc.txt

Let's check if it's already mounted, so we can use it:

$ mount | grep bin
none on /proc/sys/fs/binfmt_misc type binfmt_misc (rw)

From reading Documentation/binfmt_misc.txt, something like this
should do the trick:

# ls -l /proc/sys/fs/binfmt_misc/register
--w------- 1 root root 0 Mar 13 08:54 /proc/sys/fs/binfmt_misc/register

Write-able for root, good.

# echo ":xmms:E::mp3::/usr/bin/xmms:" > /proc/sys/fs/binfmt_misc/register


$ cat /proc/sys/fs/binfmt_misc/xmms
enabled
interpreter /usr/bin/xmms
flags:
extension .mp3

Looks promising!

$ /path/to/file.mp3
bash: /path/to/file.mp3: Permission denied

Oh wait...
$ chmod 750 /path/to/file.mp3

$ /path/to/file.mp3

Now xmms comes up and plays the file. Works as designed.;)

--
Michael Heiming (X-PGP-Sig > GPG-Key ID: EDD27B94)
mail: echo zvp...@urvzvat.qr | perl -pe 'y/a-z/n-za-m/'
#bofh excuse 286: Telecommunications is downgrading.

Lew Pitcher

unread,
Mar 13, 2005, 10:48:17 PM3/13/05
to
-----BEGIN PGP SIGNED MESSAGE-----
Hash: SHA1

Michael Heiming wrote:
> In alt.os.linux jenea <pui...@gmail.com>:
>
>>James says
>>"but you can easily use the misc_binfmt
>>functionality to declare that all .mp3 files are executables to be
>>opened
>>by XMMS"

[snip]


> # echo ":xmms:E::mp3::/usr/bin/xmms:" > /proc/sys/fs/binfmt_misc/register

[snip]


> $ chmod 750 /path/to/file.mp3
>
> $ /path/to/file.mp3
>
> Now xmms comes up and plays the file. Works as designed.;)

*Kewl*

- --
Lew Pitcher

Master Codewright & JOAT-in-training | GPG public key available on request
Registered Linux User #112576 (http://counter.li.org/)
Slackware - Because I know what I'm doing.
-----BEGIN PGP SIGNATURE-----
Version: GnuPG v1.2.4 (GNU/Linux)

iD8DBQFCNQmBagVFX4UWr64RAnEfAJ9cUIAeGdE0OILfbhQhofJWwMHBwwCg1N/u
6yvvj7ZDGMtz11crXhmeiC8=
=jN6N
-----END PGP SIGNATURE-----

Lew Pitcher

unread,
Mar 13, 2005, 10:49:20 PM3/13/05
to
-----BEGIN PGP SIGNED MESSAGE-----
Hash: SHA1

Michael,

Would you consider either submitting this as a "two cent tip" to The Linux
Gazette (http://www.linuxgazette.net/) or permitting me to do so on your behalf?


- --
Lew Pitcher

Master Codewright & JOAT-in-training | GPG public key available on request
Registered Linux User #112576 (http://counter.li.org/)
Slackware - Because I know what I'm doing.
-----BEGIN PGP SIGNATURE-----
Version: GnuPG v1.2.4 (GNU/Linux)

iD8DBQFCNQnAagVFX4UWr64RAmjkAJoCndQu9fVXDDtIbAzASMvWcnhwJACgqAwm
rCY5Pr4hqEX0IhNrRsL7J3w=
=3Xww
-----END PGP SIGNATURE-----

Chris F.A. Johnson

unread,
Mar 14, 2005, 2:00:52 AM3/14/05
to
On Sun, 13 Mar 2005 at 08:11 GMT, Michael Heiming wrote:
> In alt.os.linux jenea <pui...@gmail.com>:
>> James says
>> "but you can easily use the misc_binfmt
>> functionality to declare that all .mp3 files are executables to be
>> opened
>> by XMMS"
>> If /proc is "not a real filesystem" , hence , I can't edit
>> /proc/sys/fs/misc_binfmt/register ...
>> How could I do that?
>> google in this case is useless :(
>
> First of, never used binfmt_misc prior to your post.

First I'd heard of it, too.



> There's not always a need to google, specially if the answer is
> directly on your system, if you have (you should) installed the
> kernel sources:
>
> /usr/src/linux*/Documentation/binfmt_misc.txt

Thanks for that.

> Let's check if it's already mounted, so we can use it:
>
> $ mount | grep bin
> none on /proc/sys/fs/binfmt_misc type binfmt_misc (rw)
>
> From reading Documentation/binfmt_misc.txt, something like this
> should do the trick:
>
> # ls -l /proc/sys/fs/binfmt_misc/register
> --w------- 1 root root 0 Mar 13 08:54 /proc/sys/fs/binfmt_misc/register
>
> Write-able for root, good.
>
> # echo ":xmms:E::mp3::/usr/bin/xmms:" > /proc/sys/fs/binfmt_misc/register

I'd recommend using a different name, because xmms will be used for
several different file types:

echo ":mps:E::mp3::/usr/bin/xmms:" > /proc/sys/fs/binfmt_misc/register
echo ":ogg:E::ogg::/usr/bin/xmms:" > /proc/sys/fs/binfmt_misc/register
echo ":m3u:E::m3u::/usr/bin/xmms:" > /proc/sys/fs/binfmt_misc/register

> $ cat /proc/sys/fs/binfmt_misc/xmms
> enabled
> interpreter /usr/bin/xmms
> flags:
> extension .mp3
>
> Looks promising!
>
> $ /path/to/file.mp3
> bash: /path/to/file.mp3: Permission denied
>
> Oh wait...
> $ chmod 750 /path/to/file.mp3
>
> $ /path/to/file.mp3
>
> Now xmms comes up and plays the file. Works as designed.;)
>


--
Chris F.A. Johnson http://cfaj.freeshell.org
===================================================================
My code (if any) in this post is copyright 2005, Chris F.A. Johnson
and may be copied under the terms of the GNU General Public License

Michael Heiming

unread,
Mar 14, 2005, 3:46:16 AM3/14/05
to
In alt.os.linux Lew Pitcher <lpit...@sympatico.ca>:

> -----BEGIN PGP SIGNED MESSAGE-----
> Hash: SHA1

> Michael Heiming wrote:
>> In alt.os.linux jenea <pui...@gmail.com>:
>>
>>>James says
>>>"but you can easily use the misc_binfmt
>>>functionality to declare that all .mp3 files are executables to be

[..]

>> /usr/src/linux*/Documentation/binfmt_misc.txt
[..]

> Michael,

> Would you consider either submitting this as a "two cent tip" to The Linux
> Gazette (http://www.linuxgazette.net/) or permitting me to do so on your behalf?

Hi Lew!

Yes please! Perhaps add what Chris suggested and keep our names
to add some glory for us.;)

--
Michael Heiming (X-PGP-Sig > GPG-Key ID: EDD27B94)
mail: echo zvp...@urvzvat.qr | perl -pe 'y/a-z/n-za-m/'

#bofh excuse 195: We only support a 28000 bps connection.

Birre

unread,
Mar 14, 2005, 11:55:54 AM3/14/05
to

You are not ready for Linux, you do the biggest mistake ever by trying to change things before
you learn how it works.

The permission bits has some meaning, if you can't write to a file with perm 400 , you can't write
to it by adding other bits for you or others 600, 700 , 666 ,777 , you just sabotage the system.

And it's not +777 , its chmod 777 or chmod +rwx

But as other write, /proc is not a normal filesystem

But please, never change mode to 777 , never set text,data files to executable files, you will just crash
your system.

Go back to Windows, or start to read your manuals, accept the way it works and figure out why it works like that,
then you can try to find something nobody else thought about the last 30 years.

Or at least go away from the root shell , and use your desktop tools.


/bb

Lew Pitcher

unread,
Mar 14, 2005, 9:06:42 PM3/14/05
to
-----BEGIN PGP SIGNED MESSAGE-----
Hash: SHA1

Michael Heiming wrote:
> In alt.os.linux Lew Pitcher <lpit...@sympatico.ca>:
[snip]


>>Would you consider either submitting this as a "two cent tip" to The Linux
>>Gazette (http://www.linuxgazette.net/) or permitting me to do so on your behalf?
>
> Hi Lew!
>
> Yes please! Perhaps add what Chris suggested and keep our names
> to add some glory for us.;)

Done!

For the record, my submission to t...@linuxgazette.net (The Answer Gang at
Linux Gazette) reads...

Over in news:alt.os.linux, a reader posted a question that asked how to make
Linux use "file associations" (sort of like MSWindows) so that the user just
types the name of the data file at the commandline, and the sutiable
application starts up and processes it. The example was wanting xmms to play
an MP3 just by typing the MP3's filename at the command prompt.

This lead into a discussion amongst various alt.os.linux participants,
primarily Michael Heiming and Chris F.A. Johnson, about "binfmt_misc", and
how it could be used to satisfy MSWindow'ish "file associations". For those
who don't know, you can "register" a command interpreter through a /proc
entry, so that, when you try to run a file that needs that command
interpreter, the system will start up the program for you. This is how Linux
recognizes executable shell scripts in order to start the shell interpreter
on them, and how it recognizes executable java byte code, in order to run the
java interpreter on it, when you type it's name at the command prompt.

To use this feature, you need to mount the "binfmt_misc" pseudo-filesystem, so
as root,
mount -t binfmt_misc none /proc/sys/fs/binfmt_misc
(or add the appropriate line to your /etc/fstab, and have it mounted
automatically at the next boot). Now, (again, as root) tell Linux what
interpreter to use by "echo"ing an association string into
the /proc/sys/fs/binfmt_misc/register pseudo-file. In this case, we want to
the string to indicate that any 'executable' file with the 'extension'
of .mp3 is to be interpreted by /usr/bin/xmms, so the
registration strings are


echo ":xmms:E::mp3::/usr/bin/xmms:" > /proc/sys/fs/binfmt_misc/register

echo ":mps:E::mp3::/usr/bin/xmms:" >/proc/sys/fs/binfmt_misc/register
echo ":ogg:E::ogg::/usr/bin/xmms:" >/proc/sys/fs/binfmt_misc/register
echo ":m3u::E:m3u::/usr/bin/xmms:" >/proc/sys/fs/binfmt_misc/register

Now, when we (as a regular user)
~ $ chmod u+x my_life_changed.mp3
and then
~ $ my_life_changed.mp3
up pops XMMS and the music plays on.

The format and variations of the "registration" string are documented
in /usr/src/linux/Documentation/binfmt_misc.txt.

Kewl, eh?

My thanks to Michael Heiming and Chris F. A. Johnson for pointing out
how to do this.

- --
Lew Pitcher

Master Codewright & JOAT-in-training | GPG public key available on request
Registered Linux User #112576 (http://counter.li.org/)
Slackware - Because I know what I'm doing.
-----BEGIN PGP SIGNATURE-----
Version: GnuPG v1.2.4 (GNU/Linux)

iD8DBQFCNkMxagVFX4UWr64RAuN3AKDOWz27iwZfjee+HxuxCLJg3+l6RQCgwX5p
aR/6rhJ3Xhd1lrU+tRkP1WM=
=brMe
-----END PGP SIGNATURE-----

Lew Pitcher

unread,
Mar 14, 2005, 9:08:43 PM3/14/05
to
-----BEGIN PGP SIGNED MESSAGE-----
Hash: SHA1

Lew Pitcher wrote:
[snip]


> the registration strings are
> echo ":xmms:E::mp3::/usr/bin/xmms:" > /proc/sys/fs/binfmt_misc/register
> echo ":mps:E::mp3::/usr/bin/xmms:" >/proc/sys/fs/binfmt_misc/register
> echo ":ogg:E::ogg::/usr/bin/xmms:" >/proc/sys/fs/binfmt_misc/register
> echo ":m3u::E:m3u::/usr/bin/xmms:" >/proc/sys/fs/binfmt_misc/register

Gaak!! I'll have to correct that last line; I misplaced a colon.

[snip]
- --
Lew Pitcher

Master Codewright & JOAT-in-training | GPG public key available on request
Registered Linux User #112576 (http://counter.li.org/)
Slackware - Because I know what I'm doing.
-----BEGIN PGP SIGNATURE-----
Version: GnuPG v1.2.4 (GNU/Linux)

iD8DBQFCNkOragVFX4UWr64RAv8kAJ9wfcEWAqk0xkXl7H7rifczxZOULgCeIoYI
uCf8apCLwdNi/E3RB8WjL0k=
=tJZc
-----END PGP SIGNATURE-----

Jason F.

unread,
Mar 14, 2005, 10:29:23 PM3/14/05
to

I hate it when my xmms playlist gets clobbered, so I changed the example
to use a wrapper script (as per the doc hint) in order to pass the
"--enqueue" option, and I discovered a tiny bug (by design?) in that I
wasn't able to OVERWRITE a previously registered name with a new
interpreter. I had to first REMOVE the old association (by echo'ing -1)
and then add the new one. So I have this, for example
(~/bin/associatemp3.sh):

#!/bin/sh
# this associates an interpreter to use with a +x'd file
echo -1 > /proc/sys/fs/binfmt_misc/xmms
echo -1 > /proc/sys/fs/binfmt_misc/mps
echo -1 > /proc/sys/fs/binfmt_misc/ogg
echo -1 > /proc/sys/fs/binfmt_misc/m3u
#exit
echo ":xmms:E::mp3::/usr/local/bin/xmms-enqueue.sh:" >
/proc/sys/fs/binfmt_misc/register
echo ":mps:E::mp3::/usr/local/bin/xmms-enqueue.sh:" >
/proc/sys/fs/binfmt_misc/register
echo ":ogg:E::ogg::/usr/local/bin/xmms-enqueue.sh:" >
/proc/sys/fs/binfmt_misc/register
echo ":m3u:E::m3u::/usr/local/bin/xmms-enqueue.sh:" >
/proc/sys/fs/binfmt_misc/register

And the simple wrapper script:

#!/bin/sh
/usr/bin/xmms --enqueue $*


Anyway, thanks for this handy tip, though I don't expect to use it very
often as konqueror is more than capable and just /slightly/ easier to
update. :)

0 new messages