Set icon and run action for a file type quickly

How to do things, solutions, recipes, tutorials
Post Reply
Message
Author
User avatar
Rattlehead
Posts: 368
Joined: Thu 11 Sep 2008, 11:40

Set icon and run action for a file type quickly

#1 Post by Rattlehead »

Initial problem: some file types in Rox-Filer are not recognized out-of-the-box, so you cannot use the "set icon" or "set run action" option on them (they have generic names like "XML application", so making changes will have unintended consequences on other files).

This happens because Rox Filer uses a pre-made list of applications called "mime types" to know which programs are installed in the system. When the program you've installed is not in that list, Rox cannot associate a file type to it, and therefore you won't be able to execute it with a simple clic or enter press.

I found a first workaround to this problem that I documented here: http://murga-linux.com/puppy/viewtopic.php?t=106994. But such system was created before I knew how to modify the Mime types, so this current post supersedes that one.

This page in the Puppy wiki shows how to modify Mime types for your purposes:

http://www.puppylinux.org/wikka/HowToAddMIMEType

It seems to create a new mime-type all you need is adding 4 lines of code per program. The wiki offers two systems to do that: the first, which I haven't tried, is automated, running the update-mime command. It has the drawback that it requires to have installed the devx file that corresponds to our Puppy, and also, there are certain Puppy versions in which it doesn't work (version 4, I think).

The second option shows you how to create manually one single new mime type entry, like I said just adding 4 lines of code, in different places. I've simply taken the code from the wiki and added user input to automate things a bit. Here is the script I use:

Code: Select all

#!/bin/sh

#add mime-type (without using update-mime-database)
clear
echo "Application name?"

read a

echo "File termination (without the .)?"
read b

echo application/x-$a-project:*.$b >> /usr/share/mime/globs
echo 50:application/x-$a-project:*.$b >> /usr/share/mime/globs2
echo application/x-$a-project text/xml >> /usr/share/mime/subclasses
echo application/x-$a-project >> /usr/share/mime/types

echo "New MIME type added. You might need to restart the graphic server"
Regarding the 50: in the code, it's interesting to remark that all the entries in my /usr/share/mime/globs2 had that number and no other. In my experience, that's always the case, but if someone knows of cases in which that number should be different, please add the information to this thread!

So the full process to have a new file type configured goes like this (I'll use the Hydrogen drumming machine, whose file termination is .h2song, as an example):

1) Run the script in a terminal. First reply, "hydrogen",enter, second "h2song", enter

The new Mime type is created; now Rox-Filer recognizes an application called Hydrogen, but the Mime type is still empty; we have to tell Rox what to open and what icon to show with the files.

2) To configure which program will open the file: In Rox-filer, go to one file of the type you just configured, and right click on it. Select "set run action", and type the command that must execute that file ("hydrogen -s $1" or "hydrogen -s $@" in this case. The final characters are like a placeholder that tells the computer "whatever file we're pointing at").

Now click or press enter on an .h2song, and it should be open by Hydrogen directly.

3)Now we have to configure the icon that all .h2song files will show. There should be an easier way to do this, by adding the icon image directly in some of ROX's folders and having it automatically associated, but I haven't been able to configure it, so here's what I have:

Again in Rox-Filer, right click on the file of the kind you want to configure, and select "set icon". A window will open. On top there are two options. Mark the one that has the name of your program in it. Drag the icon image you want to the window, and you're done.

Regarding icon images, I've found that they tend to be scattered around the system tree (because programs get installed in very diverse places), so what I do to find the icons in my system is:

(DON'T BOTHER WITH THIS PROCESS BELOW
Use Jwm menu>Graphic>Icon finder instead. Far more useful and clear.)


1) make a list of everything that might contain an icon, and put it in a text file:

Code: Select all

find / -name '*icon*' > icons_paths
(It will take a while. Put that file in some safe place and you can reuse it without having to run the find command every time)

2) When the time comes when you need an icon for a certain program, filter that list to show only the lines that contain that program

Code: Select all

cat icons_paths | grep hydrogen
You'll get a list of paths. Open with rox-filer one of them that you think suitable, and you'll find an icon and can drag it.

This system is easier done than explained, I thought some people might find it helpful or, at the very least, get out of this some insights on how the MIME types work.
Last edited by Rattlehead on Wed 07 Sep 2016, 21:47, edited 1 time in total.

User avatar
MochiMoppel
Posts: 2084
Joined: Wed 26 Jan 2011, 09:06
Location: Japan

Re: Set icon and run action for a file type quickly

#2 Post by MochiMoppel »

Rattlehead wrote:The wiki offers two systems to do that: the first, which I haven't tried, is automated, running the update-mime command.
Why didn't you at least try? The file /usr/bin/update-mime-database is included in all Puppies I know and is not buried in the devx package. If it really is you can still extract it from there. As explained in the Wiki all you need to do is to create a new XML file, e.g. to create a new MIME type mochi, associated with the file extension .moc, create a new XML file /usr/share/mime/packages/mochi.xml :

Code: Select all

<?xml version="1.0"?>
<mime-info xmlns='http://www.freedesktop.org/standards/shared-mime-info'>
  <mime-type type="application/mochi">
    <comment>mochi test</comment>
    <glob pattern="*.moc"/>
  </mime-type>
</mime-info>
Then run

Code: Select all

update-mime-database /usr/share/mime
This will update several files. Now you can right click on .moc files in ROX and set a Run action.

This is the "official" way. Please forget the second method. You will manually edit files that start with a big "DO NOT EDIT!". There is a reason for that.

User avatar
LazY Puppy
Posts: 1934
Joined: Fri 21 Nov 2014, 18:14
Location: Germany

#3 Post by LazY Puppy »

I gave this a try to create a mime-type for audacity. Audacity uses xml files by using extension .aup.

Used a plain tahr 6.0.2 for testings - only changes was DE keyboard layout.

So I tested with the two different xml files one by one (rebooted after each test):

Code: Select all

<?xml version="1.0"?>
<mime-info xmlns='http://www.freedesktop.org/standards/shared-mime-info'>
  <mime-type type="application/audacity">
    <comment>Audacity Project</comment>
    <glob pattern="*.aup"/>
  </mime-type>
</mime-info>

Code: Select all

<?xml version="1.0"?>
<mime-info xmlns='http://www.freedesktop.org/standards/shared-mime-info'>
  <mime-type type="application/aup">
    <comment>Audacity Project</comment>
    <glob pattern="*.aup"/>
  </mime-type>
</mime-info>
Original globs has 750 lines, original globs2 has 745 lines of text.

After executing update-mime-database /usr/share/mime in terminal file globs returns by 24 lines of text and file globs2 returns also by 24 lines of text.

Xml files appeared as plain text files in rox filer window, after restarting X all icons are gone - that said, all files are presented by the red/white triangle with the question mark in it.

No save file in use for that testings.

That's weird...
RSH

"you only wanted to work your Puppies in German", "you are a separatist in that you want Germany to secede from Europe" (musher0) :lol:

No, but I gave my old drum kit away for free to a music store collecting instruments for refugees! :wink:

User avatar
MochiMoppel
Posts: 2084
Joined: Wed 26 Jan 2011, 09:06
Location: Japan

#4 Post by MochiMoppel »

LazY Puppy wrote:I gave this a try to create a mime-type for audacity. Audacity uses xml files by using extension .aup
.And? Did it work? I mean, were you able to create a mime type audacity?
Used a plain tahr 6.0.2 for testings
:lol: tahrpup....hmmm :lol:
I checked tahrpup and found only a small fraction of XML files that are necessary to (re)build the globs file. Why does tahrpup do this? Expecting that nobody would ever run update-mime-database or that everybody would use the crude manual method described in the Wiki? And why are the application and packages folders left and not scrapped as well?
That's weird...
That's one way to describe it.
Attachments
MIME-slacko-tahrpup.png
(91.22 KiB) Downloaded 1121 times

User avatar
LazY Puppy
Posts: 1934
Joined: Fri 21 Nov 2014, 18:14
Location: Germany

#5 Post by LazY Puppy »

Yes, audacity mime type was created and Run action could be set.

Though, since it destroyed everything else in tahr 602 it is useless.

Will give this a try in Slacko.
RSH

"you only wanted to work your Puppies in German", "you are a separatist in that you want Germany to secede from Europe" (musher0) :lol:

No, but I gave my old drum kit away for free to a music store collecting instruments for refugees! :wink:

User avatar
MochiMoppel
Posts: 2084
Joined: Wed 26 Jan 2011, 09:06
Location: Japan

#6 Post by MochiMoppel »

LazY Puppy wrote:Though, since it destroyed everything else in tahr 602 it is useless.
Not useless, it's a killer application :lol:

User avatar
666philb
Posts: 3615
Joined: Sun 07 Feb 2010, 12:27
Location: wales ... by the sea

#7 Post by 666philb »

here's how i got the mime for audacity working....

first off, make sure that tahrpup is fully up-to date as there was a specific bugfix for this problem over a year ago!

install the desktop-file-utils pet below then in a terminal

Code: Select all

update-desktop-database /usr/share/applications
update-mime-database /usr/share/mime
you might have to restart x for ROX to see the change...you can then use 'set run action'
Attachments
snapshot-1.png
(5.43 KiB) Downloaded 846 times
desktop-file-utils.pet
although desktop-file-utils is available in the PPM it overwrites puppys /usr/share/applications/defaults.list. so use this .pet
(60.6 KiB) Downloaded 233 times
Last edited by 666philb on Sat 03 Sep 2016, 07:34, edited 1 time in total.
Bionicpup64 built with bionic beaver packages http://murga-linux.com/puppy/viewtopic.php?t=114311
Xenialpup64, built with xenial xerus packages http://murga-linux.com/puppy/viewtopic.php?t=107331

User avatar
666philb
Posts: 3615
Joined: Sun 07 Feb 2010, 12:27
Location: wales ... by the sea

#8 Post by 666philb »

MochiMoppel wrote: I checked tahrpup and found only a small fraction of XML files that are necessary to (re)build the globs file. Why does tahrpup do this? Expecting that nobody would ever run update-mime-database or that everybody would use the crude manual method described in the Wiki? And why are the application and packages folders left and not scrapped as well?
That's weird...
That's one way to describe it.
this was fixed in 6.0.5 ... it was also fixed by an update for 6.0.2 & 6.0

Code: Select all

16/06/2015 added missing files for update-mime-database and reinstated old hacks-postinstall...rg66 
Bionicpup64 built with bionic beaver packages http://murga-linux.com/puppy/viewtopic.php?t=114311
Xenialpup64, built with xenial xerus packages http://murga-linux.com/puppy/viewtopic.php?t=107331

User avatar
LazY Puppy
Posts: 1934
Joined: Fri 21 Nov 2014, 18:14
Location: Germany

#9 Post by LazY Puppy »

Thanks.

This was the first issue ever I ran into in tahr 6.0.2.

So, time to switch over to 6.0.5.
RSH

"you only wanted to work your Puppies in German", "you are a separatist in that you want Germany to secede from Europe" (musher0) :lol:

No, but I gave my old drum kit away for free to a music store collecting instruments for refugees! :wink:

musher0
Posts: 14629
Joined: Mon 05 Jan 2009, 00:54
Location: Gatineau (Qc), Canada

#10 Post by musher0 »

Making a note of this. Thanks, Rattlehead!
musher0
~~~~~~~~~~
"You want it darker? We kill the flame." (L. Cohen)

User avatar
Rattlehead
Posts: 368
Joined: Thu 11 Sep 2008, 11:40

#11 Post by Rattlehead »

@Musher0: You're welcome, glad someone found some use out of this! :)

I may have made a bit of a mess by forgetting to mention that this method was tested in Lupu. I guess I assumed all Puppies=same Rox, therefore same working, but maybe that's not the case. I apologize.

@Mochimoppel:

I didn't try the first system first because it seemed a very big drag just to get the 3 icons that I needed, and the possibilities to screw something far outweighted the possibility of succeeding, at least for me who hadn't ever used any of the two methods before. Here is the quotation from the wiki for method one:
This method cannot be used in standard Puppy.
Ouch. What does "standard Puppy mean"? The "main" Puppy line (Puppy 1, 2, 3, 4, 5?) Like I said, I use Lupu, Puppy 5.2., therefore that first line disqualifies me already.
It requires XML description files and command update-mime-database. These are often provided by loading the appropriate devx sfs.
Often, but not always. If they're not, you have to find out what to do next. The wiki doesn't tell. More steps added. Add this uncertainty factor to the previous one. Have we broken something yet? Let's go for the next reassuring instruction:
Caution: running update-mime-database without the XML descriptions will remove most of your MIME-types stored in globs, globs2 etc.
To make things worse, terminal autocompletion showed not 1 but 2 results for update-mime: update-mime and something called update-mime-database. Yet another duplication of the possibilities of something going wrong. (Yeah, the wiki is clear about using 'update-mime', but when was that wiki entry written?)

In addition, even if the whole process worked correctly, I wasn't even sure that the mysterious update script would contain the 3 programs I needed! Updating all that stuff only for 3 programs looked like overkill, and the result at the end of all the hurlyburly could be that... nothing happened!

Reaching that point, this power user started to feel rather powerless: :P So the next sentence came in like a glass of fresh water:
To add a MIME-type without needing add all descriptions see below.
So I tried #2 first, and it worked as a charm. Had #2 not worked, I would have moved to attempting the more convoluted #1. Agreed, maybe editing a file that starts with a big "DON'T EDIT THIS" is a bit of a scotch tape solution, but it works for me, and up to now I haven't found any additional disadvantages. If someone knows of problems caused by doing this (besides being un-elegant), please post the information here, this is just my method; after all, wiki means "what I know is", doesn't it? :)

User avatar
Puppus Dogfellow
Posts: 1667
Joined: Tue 08 Jan 2013, 01:39
Location: nyc

i used Mochi's version with success in precise, xenial32,

#12 Post by Puppus Dogfellow »

unicorn didnt have the mime update script, so i copied it over from precise after phil's tahr fix failed, and wiped out a whole bunch of file associations. will give Rattlehead's method (can you batch associate?) on a fresh unicorn (spin (p6), though i'm sure it'd've played out the same in an original). anyway, here's the part that went well (seems i can further pare down and simplify the mini version of my micro word processor....which leads to a step that i'll fill in at the end of the post):

geany /usr/share/mime/packages/pwn.xml:

Code: Select all

<?xml version="1.0"?>
<mime-info xmlns='http://www.freedesktop.org/standards/shared-mime-info'>
<mime-type type="application/def">
<comment>nwp/pwn/anubis/anuupuus word processor/run defbrowser deftexteditor on file(s)</comment>
<glob pattern="*.ser"/>
<glob pattern="*.san"/>
<glob pattern="*.mon"/>
<glob pattern="*.pwn"/>
<glob pattern="*.nwp"/>

<glob pattern="*.mono"/>
</mime-type>
</mime-info>


geany /usr/share/mime/packages/nwp.xml:

Code: Select all

<?xml version="1.0"?>
<mime-info xmlns='http://www.freedesktop.org/standards/shared-mime-info'>
<mime-type type="application/pwp">
<comment>nwp/pwn/anubis/anuupuus word processor/run defbrowser deftexteditor on file(s)</comment>
<glob pattern="*.sans"/>
<glob pattern="*.mons"/>
<glob pattern="*.sers"/>
</mime-type>
</mime-info>
(the above was originally one file, but i decided i'd rather be able to associate icons to templates by subcategory and not just individually, so now i've got two categories--i'm sure there's a way to do this with only one file giving you as many as you want...(i think some things in that folder show the way, but this works)).

Code: Select all

update-mime-database /usr/share/mime


#set run action:
ln -s /usr/share/applications/pwp /root/.config/rox.sourceforge.net/MIME-types/application_pwp

ln -s /usr/share/applications/def /root/.config/rox.sourceforge.net/MIME-types/application_def

#set icon:
cp -f /[/path]/application_def.png /root/.config/rox.sourceforge.net/MIME-icons/application_def.png
cp -f [/path]/application_pwp.png /root/.config/rox.sourceforge.net/MIME-icons/application_pwp.png

left out the step that involved making the desktop file and then duplicating it and running fixmenus; jwm -restart---app in question was formerly mainly just a drag and drop script; it really may not matter so long as the executable is linked or copied into the templates folder above.

anyway, thanks for the info, Rattlehead and MochiMopppel.

User avatar
Puppus Dogfellow
Posts: 1667
Joined: Tue 08 Jan 2013, 01:39
Location: nyc

alternate version of above

#13 Post by Puppus Dogfellow »

smaller version:

Code: Select all

#!/bin/sh
#no devx needed; anubis micro word processor--open concurrently templates in browser and text editor
echo application/x-def:*.mon >> /usr/share/mime/globs
echo 50:application/x-def:*.mon >> /usr/share/mime/globs2
echo application/x-def text/xml >> /usr/share/mime/subclasses
echo application/x-def >> /usr/share/mime/types
echo application/x-def:*.san >> /usr/share/mime/globs
echo 50:application/x-def:*.san >> /usr/share/mime/globs2
echo application/x-def:*.ser >> /usr/share/mime/globs
echo 50:application/x-def:*.ser >> /usr/share/mime/globs2
echo application/x-def:*.pwn >> /usr/share/mime/globs
echo 50:application/x-def:*.pwn >> /usr/share/mime/globs2
echo application/x-def:*.nwp >> /usr/share/mime/globs
echo 50:application/x-def:*.nwp >> /usr/share/mime/globs2
echo application/x-def:*.mono >> /usr/share/mime/globs
echo 50:application/x-def:*.mono >> /usr/share/mime/globs2
#echo application/x-pwp:*.mons >> /usr/share/mime/globs
#echo 50:application/x-pwp:*.mons >> /usr/share/mime/globs2
#echo application/x-pwp text/xml >> /usr/share/mime/subclasses
#echo application/x-pwp >> /usr/share/mime/types
#^add extentions to a category or add categories (icon and run action "differentiators") with this template
echo application/x-pwp:*.mons >> /usr/share/mime/globs
echo 50:application/x-pwp:*.mons >> /usr/share/mime/globs2
echo application/x-pwp text/xml >> /usr/share/mime/subclasses
echo application/x-pwp >> /usr/share/mime/types
echo application/x-pwp:*.sans >> /usr/share/mime/globs
echo 50:application/x-pwp:*.sans >> /usr/share/mime/globs2
echo application/x-pwp:*.sers >> /usr/share/mime/globs
echo 50:application/x-pwp:*.sers >> /usr/share/mime/globs2

#(copy in def pwp desktop files); fixmenus jwm -restart
#set run action:
ln -s /usr/share/applications/pwp /root/.config/rox.sourceforge.net/MIME-types/application_pwp

ln -s /usr/share/applications/def /root/.config/rox.sourceforge.net/MIME-types/application_def

#set icon:
cp -f /nwp/wp/application_def.png /root/.config/rox.sourceforge.net/MIME-icons/application_def.png
cp -f /nwp/wp/application_pwp.png /root/.config/rox.sourceforge.net/MIME-icons/application_pwp.png


#you can change icons or run actions again after the fact through the rox right click menu. the file manager will use symlinks (ln -s), but copying the files (cp -f) does the same thing. code above does one of each because, although links are smaller, cp -f doesn't get any lip.

tried the previous version in tahr64 and had to load the devx to get it to work--i was remastering the pup and meant to include the feature, and it seemed that may involve more than just copying over that update_database file (wikki says it needs to read other files also not ordinarily included). this seemed easier (and lighter) than tracking them down. i haven't tried it yet, but it seems as "official" as the other version. at any rate, a user shouldn't have to load the devx to use a file type the machine's otherwise incurably ignorant of. maybe i'll just tuck the script into a start up folder--have three manual frugals waiting i can try it out in.

--------------

here's a screen shot showing the icons changing when the extension changes (templates or whatever will fill out the file so its contents or format match its category can be added after the fact--machine will try to open the file the way you told it to (not shown)):
Attachments
mimetype-icon_change.gif
(26.14 KiB) Downloaded 648 times

User avatar
Rattlehead
Posts: 368
Joined: Thu 11 Sep 2008, 11:40

#14 Post by Rattlehead »

Speaking of icons...

I just stumbled upon an excellent program called "Icon finder" (Jwm Menú>Graphic>Icon finder) that finds the icons in the computer in a more eficient (and graphic) way than the one I used...

User avatar
Puppus Dogfellow
Posts: 1667
Joined: Tue 08 Jan 2013, 01:39
Location: nyc

#15 Post by Puppus Dogfellow »

Code: Select all

#!/bin/sh
#nwp64.4
echo application/x-def:*.mon >> /usr/share/mime/globs
echo 50:application/x-def:*.mon >> /usr/share/mime/globs2
echo application/x-def text/xml >> /usr/share/mime/subclasses
echo application/x-def >> /usr/share/mime/types
echo application/x-def:*.san >> /usr/share/mime/globs
echo 50:application/x-def:*.san >> /usr/share/mime/globs2
echo application/x-def:*.ser >> /usr/share/mime/globs
echo 50:application/x-def:*.ser >> /usr/share/mime/globs2
echo application/x-def:*.pwn >> /usr/share/mime/globs
echo 50:application/x-def:*.pwn >> /usr/share/mime/globs2
echo application/x-def:*.nwp >> /usr/share/mime/globs
echo 50:application/x-def:*.nwp >> /usr/share/mime/globs2
echo application/x-def:*.mono >> /usr/share/mime/globs
echo 50:application/x-def:*.mono >> /usr/share/mime/globs2
echo application/x-def:*.def >> /usr/share/mime/globs
echo 50:application/x-def:*.def >> /usr/share/mime/globs2
echo application/x-def2:*.def2 >> /usr/share/mime/globs
echo 50:application/x-def2:*.def2 >> /usr/share/mime/globs2
echo application/x-def2 text/xml >> /usr/share/mime/subclasses
echo application/x-def2 >> /usr/share/mime/types
echo application/x-def3:*.def3 >> /usr/share/mime/globs
echo 50:application/x-def3:*.def3 >> /usr/share/mime/globs2
echo application/x-def3 text/xml >> /usr/share/mime/subclasses
echo application/x-def3 >> /usr/share/mime/types
echo application/x-pwp:*.mons >> /usr/share/mime/globs
echo 50:application/x-pwp:*.mons >> /usr/share/mime/globs2
echo application/x-pwp text/xml >> /usr/share/mime/subclasses
echo application/x-pwp >> /usr/share/mime/types
echo application/x-pwp:*.sans >> /usr/share/mime/globs
echo 50:application/x-pwp:*.sans >> /usr/share/mime/globs2
echo application/x-pwp:*.sers >> /usr/share/mime/globs
echo 50:application/x-pwp:*.sers >> /usr/share/mime/globs2
#(copy in def pwp desktop files); fixmenus jwm -restart
#set run action:
mkdir -p /root/.config/rox.sourceforge.net/MIME-types
ln -s /usr/share/applications/pwp /root/.config/rox.sourceforge.net/MIME-types/application_x-pwp
ln -s /usr/share/applications/def /root/.config/rox.sourceforge.net/MIME-types/application_x-def
#set icon:
cp -f //usr/share/applications/icons-alt/inpare9.xpm /root/.config/rox.sourceforge.net/MIME-icons/application_x-def.png
cp -f /usr/share/applications/icons-alt/p2e0.xpm  /root/.config/rox.sourceforge.net/MIME-icons/application_x-pwp.png
[...]
Posted: Tue 06 Sep 2016, 20:23 Post subject: alternate version of above
Subject description: untested but i think it will work. am i overlooking something?
had the names on the icons wrong for one thing (left out a -x), but that method of setting them works so inconsistently (or i confused something by repeatedly swapping back and forth so many times) i ended up putting an alt-icons folder in usr//share/applications just so i could easily right-click assign them--it's a useless part of the script. :lol:

maybe messing with that /root/.config/rox.sourceforge.net/ROX-Filer/globicons file is a better way?(
Rattlehead
Posted: Wed 07 Sep 2016, 17:44 Post subject:
Speaking of icons...
[...]...
)

anyway, i used it in a pinstall script for a pet that was making most of a remaster and the copies all have the four extensions register as unique entities that can get their own programs and icon assignments (which is cool/i'm over the disappointment and inconvenience). :D

sheldonisaac
Posts: 902
Joined: Mon 22 Jun 2009, 01:36
Location: Philadelphia, PA

#16 Post by sheldonisaac »

Rattlehead (in part) wrote:
To add a MIME-type without needing add all descriptions see below.
So I tried #2 first, and it worked as a charm.
Many thanks, Rattlehead!!

It did for me also, to let FBReader open .mobi files.

Sheldon
Dell E6410: BusterPup, BionicPup64, Xenial, etc
Intel DQ35JOE, Dell Vostro 430
Dell Inspiron, Acer Aspire One, EeePC 1018P

Post Reply