How to make Rox filer open the right programs

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

How to make Rox filer open the right programs

#1 Post by Rattlehead »

With certain files, Rox Filer has a hard time detecting which program must use to open them. The problem seems to be that it checks the type of file not by looking on the file name termination, but on something called "Mime types".

As a result, different kind of files, with different file extensions, can share the same Mime type and therefore Rox will not allow them to open with different programs: if you change the default action for one of them with the "Set run action" option, it will change for both, so one of them will be wrong.

The baseline result is that you cannot open one of those files by simply clicking on them or press enter; it will open with a wrong program and generate a weird error, so you have to select them, press "!" for the execute command, and write the name of the appropriate program time after time. A drag and a continuous source of errors.

Here is a recent way I found to circumvent that problem; for those programs who share the same Mime type, we'll send control to a bash script, which will the one in charge of doing the checking and execute the correct program. Here it is:

Code: Select all

#!/bin/bash

#Get extension
 filename=`basename $1`
 fileext=${filename##*.}

case $fileext in

h2song)

hydrogen -s $1 &
;;

aup)

audacity $1 &

;;

ardour)

ardour2 $1 &
;;

esac
Now we need to tell Rox to send the files to it. We Select one of the conflicting files -anyone will do-, execute "set run action" (keyboard shortcut "*"), and in the field "Enter a shell command", type the complete path to the script, keeping the "$@" symbol at the end (a wildcard that means current selection). In my case the line would be: /root/my-scripts/rox-wrapper.sh "$@". Click "Use command" to save the changes.

As Rox does not differentiate between the types of files, we only need to do this change once, and it will be applied automatically to the other files. Finally, in each of the "case" entries in the script, we put one file termination that we want to use, and the program with which we want it to be executed. In my example script, it recognizes three kind of files: Hydrogen, Audacity, and Ardour. Previously to this trick, Rox filer considered the three of them to be Ardour, so it was easy to make mistakes when trying to open something. Other programs where I remember this happens are the Xmind mind mapping software, and the Portabase database.

Hope some of you find this little trick helpful :)

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

#2 Post by LazY Puppy »

If clicking a file by holding a shift key down, Rox will send the file to /usr/local/bin/defaulthandler (the file is interpeted as text file then, so the defaulthandler will send it to defaulttexteditor).

Just edit /usr/local/bin/defaulthandler to the like.
In between of case and esac in my defaulthandler script wrote: # SFS Modules
iso|ISO)
filemnt "$FFILE"
;;

# SFS Modules
sfs|SFS)
sfs-handler "$FFILE"
;;

# Archives
gz|GZ|bz|BZ|tar*|TAR*|zip|ZIP|tgz|TGZ)
/usr/bin/xarchive "$FFILE"
;;

# Install Packages
deb|DEB|pet|PET)
/usr/local/petget/petget "$FFILE"
;;

# Plain Text Documents
txt|TXT|lst|LST|cfg|CFG|specs|SPECS|rc|RC|sh|SH|py|PY|js|JS|json|JSON)
/usr/local/bin/defaulttexteditor "$FFILE"
;;

# Word Office Document
doc|DOC|rtf|RTF|docx|DOCX|odt|ODT)
/usr/local/bin/defaultwordprocessor "$FFILE"
;;

# Spreadsheet Office Documents
xls|XLS|gnumeric|GNUMERIC|odc|ODC|ods|ODS)
/usr/local/bin/defaultspreadsheet "$FFILE"
;;

# HTML/XML and similar Documents
htm*|HTM*|xml|XML|css|CSS|php|PHP)
/usr/local/bin/defaulttexteditor "$FFILE"
;;

# Image Documents 1 - GIMP should be the 'defaultimageeditor'
xcf|XCF|ico|ICO|psd|PSD|gs|GS)
/usr/local/bin/defaultimageeditor "$FFILE"
;;

# Image Documents 2 - ViewNior
bmp|BMP|jpg|JPG|jpeg|JPEG|png|PNG|gif|GIF|tif*|TIF*|xpm|XPM)
#/usr/local/bin/defaultimageeditor "$FFILE"
[ "$IMGEDITNOVIEW" = "true" ] && /usr/local/bin/defaultimageeditor "$FFILE" || /usr/local/bin/defaultimageviewer "$FFILE"
;;

# Image Documents 3 - Corel Photopaint
cpt|CPT)
/usr/local/bin/defaultcorelphotoeditor "$FFILE"
;;

# Image Documents 3 - Corel Draw
cdr|CDR)
/usr/local/bin/defaultcoreldraweditor "$FFILE"
;;

# Image Documents 3 - Corel Dream 3D
d3d|D3D)
/usr/local/bin/defaultcoreldreameditor "$FFILE"
;;

# PDF/PostScript Documents
pdf|PDF|ps|PS|eps|EPS)
/usr/local/bin/defaultpdfviewer "$FFILE"
;;

# Audio Documents
mp3|MP3|wav|WAV|flac|FLAC|ogg|OGG)
#/usr/local/bin/defaultaudioeditor "$FFILE"
#/usr/local/bin/defaultplayer "$FFILE"
[ "$AUDEDITNOPLAY" = "true" ] && /usr/local/bin/defaultaudioeditor "$FFILE" || /usr/local/bin/defaultmediaplayer "$FFILE"
;;

# Video Documents
mp4|MP4|mpg|MPG|mpeg|MPEG|avi|AVI|mkv|MKV)
/usr/local/bin/defaultmediaplayer "$FFILE"
;;

#---------------------------
# End of default Definitions
#---------------------------

# Any else Documents
*)
#/usr/local/bin/defaulttexteditor-bin "$FFILE"
"$BINSDIR"/defaulttexteditor-bin "$FFILE"
;;
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

#3 Post by MochiMoppel »

The wrapper script proposed by Rattlehead is supposed to open the "right program" with a simple click, not a Shift-click.
LazY Puppy wrote:If clicking a file by holding a shift key down, Rox will send the file to /usr/local/bin/defaulthandler
Does it? I've never seen this in any Puppy, and if it would, it would be a bad idea - at least if it would open the slightly messy defaulthandler in my Slacko 5.6. Does anyone know why this defaulthandler exists?

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

#4 Post by LazY Puppy »

MochiMoppel wrote:The wrapper script proposed by Rattlehead is supposed to open the "right program" with a simple click, not a Shift-click.
LazY Puppy wrote:If clicking a file by holding a shift key down, Rox will send the file to /usr/local/bin/defaulthandler
Does it? I've never seen this in any Puppy, and if it would, it would be a bad idea - at least if it would open the slightly messy defaulthandler in my Slacko 5.6. Does anyone know why this defaulthandler exists?
This is default in Linux/Rox. Any file clicked by holding shift key down is handled/interpreted as .txt file and will go to defaulthandler/defaulttexteditor.

I know about Rattlehead's proposal since I did understand the post's content.

Just wanted to show how I do send files to its programs easily.

Clicking a .jpg file usually ends in image viewer. When I'm holding shift key down, it ends up in image editor which is The GIMP in my setup.

If you have a plain defaulthandler click a binary holding shift key down - text editor will appear on the screen (though, the binary will not load, of course).

In my opinion, it's not a bad idea. It gives control over files without to change default behavior in general.
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
Rattlehead
Posts: 368
Joined: Thu 11 Sep 2008, 11:40

#5 Post by Rattlehead »

@Lazy Puppy, thank you for the info on defaulthandler, I didn't know it existed.

I've been trying to look into it, as it would be great to have a set of two possible executable programs (for example for cases like what you mention, an image that sometimes you just want to see but sometimes want to edit). There is something I don't understand. In my /usr/local/bin/defaulthandler, which I have never touched, there is already a case command with several options. One of them is "png":

Code: Select all

 png|PNG|gif|GIF|jpg|JPG|jpeg|JPEG|xpm|XPM)
  /usr/local/bin/defaultpaint "$1"
 ;;
However, if I click+shift on a .png file, it opens in the text editor. What should I change in the script to unlock these additional options? (I've already backed it up first lol).

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

#6 Post by MochiMoppel »

LazY Puppy wrote:Any file clicked by holding shift key down is handled/interpreted as .txt file
That's the basic idea behind the "Open as text" menu item (which is the same as Shift-click)
and will go to defaulthandler/defaulttexteditor.
It will go to the defaulttexteditor, not to defaulthandler - unless your Puppy is configured to use the defaulthandler for MIME type text/plain.

I don't say that defaulthandler is a bad idea as such. Your setup of allowing a JPG file be opened either by the imageviewer or the imageeditor is a good example. It makes no sense to send a JPG file to a text editor. But this requires a careful configuration. In the current defaulthandler I see that html , pdf, rtf files are all sent to their respective default applications, i.e. simple clicking or Shift-clicking has the same effect. That's not what it should be. If I Shift-click a rtf file I do want to see the source code in an editor, if I Shift-click a html file I do want to see the mark up text in an editor, not necessarily Geany, but this is where the customization comes in. I definitely don't want to open the browser when Shift-clicking on a html file.
Rattlehead wrote:if I click+shift on a .png file, it opens in the text editor. What should I change in the script to unlock these additional options?
Nothing in this script.
When you Shift-click on any file ROX will run the script /root/Choices/MIME-types/text_plain. Edit this script and change

Code: Select all

exec defaulttexteditor "$1"
to

Code: Select all

exec defaulthandler "$1"
Or you could right click a text file and set the run action for type text/plain to defaulthandler "$@"

BTW: Hopping from wrapper script to wrapper script is an old Puppy tradition, but couldn't this be done much easier?
Instead of
ROX => /root/Choices...text_plain => defaulthandler => defaulteditor => Geany
it could be
ROX => /root/Choices...text_plain => Geany
Extension sniffing and application choice, i.e. all the logic of defaulthandler, could be handled with only one script between ROX and the application.

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

#7 Post by LazY Puppy »

In the current defaulthandler I see that html , pdf, rtf files are all sent to their respective default applications, i.e. simple clicking or Shift-clicking has the same effect. That's not what it should be. If I Shift-click a rtf file I do want to see the source code in an editor, if I Shift-click a html file I do want to see the mark up text in an editor, not necessarily Geany, but this is where the customization comes in. I definitely don't want to open the browser when Shift-clicking on a html file.
My defaulthandler script still is a modified version from old Lucid 528. It is mainly used by JWM menu pipes to send files from within $BOOTPARTITION/My-Files/SubDirs-here to its programs by a file's menu pipe entry.

My defaulttexteditor script calls defaulttexteditor-bin which is modified almost equal to the defaulthandler script - just overseen this. Didn't have a look into these files for a long time - as usual when it's still/just working.
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
Rattlehead
Posts: 368
Joined: Thu 11 Sep 2008, 11:40

#8 Post by Rattlehead »

Thank you for the explanations (sorry for the time it took me to answer).

I'd like to apply the aforementioned customization, but I find an obstacle: I open plain text files, and .otl (vim outline) files, with the set run action "gvim $@". If I use defaulthandler instead, I get the double option (mtpaint of viewnior) for images, which is great, but texts open in geany instead.

My brain is not fully engaged right now, but I think maybe I could achieve this if I modified defaulttexteditor to gvim. Do you know how to do it? If not nevermind, I'll find it somewhere in this forum I'm sure.

Sailor Enceladus
Posts: 1543
Joined: Mon 22 Feb 2016, 19:43

#9 Post by Sailor Enceladus »

I just did a similar thing to get "oga" (from ETP's thread here) to open in browser but ogg in audio player.

Here's the contents of audio.ogg:

Code: Select all

#! /bin/sh
# open oga (ogg container/opus codec) in browser

if [ "`echo "$1" | tail -c 4 | head -c 3`" == "oga" ]; then
	defaultbrowser "$@"
else
	defaultaudioplayer "$@"
fi
edit: I think this might work better (still testing random oggs with it, I needed to upgrade to file-5.27 to see "Opus"):

Code: Select all

#! /bin/sh

if [ "`file -b "$1" | grep Opus`" ]; then
	defaultbrowser "$@"
else
	defaultaudioplayer "$@"
fi
Attachments
Screenshot.png
(20.78 KiB) Downloaded 574 times
Last edited by Sailor Enceladus on Wed 08 Jun 2016, 01:00, edited 2 times in total.

User avatar
Smithy
Posts: 1151
Joined: Mon 12 Dec 2011, 11:17

#10 Post by Smithy »

Whilst people are talking about Rox, is it possible to make a progress display for files?
I have sat there waiting for the copy or move dialog box to close wondering if it has crashed when copying or moving a file (it never has crashed).

Here's an example of what I mean:
https://bash.cyberciti.biz/guide/A_prog ... uge_box%29

Maybe in a fetching green..

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

#11 Post by MochiMoppel »

Sailor Enceladus wrote: edit: I think this might work better (still testing random oggs with it, I needed to upgrade to file-5.27 to see "Opus"):

Code: Select all

#! /bin/sh

if [ "`file -b "$1" | grep Opus`" ]; then
	defaultbrowser "$@"
else
	defaultaudioplayer "$@"
fi
I think this might not work at all :lol:
1) I downloaded the sample oga file from ETP's thread (Old Love.oga), and file -b "Old Love.oga" returns "Ogg data" - no Opus :cry:

2) I downloaded a sample ogg file, and in Slacko 5.6 the MIME type for this file is x-vorbis+ogg, so ROX would not read your audio_ogg script (ROX would expect an audio_x-vorbis+ogg script)

Your best bet might be to do the extension sniffing in the defaultaudioplayer script. That's the place where all (?) music files pass through and where you can send them to the most suitable application.

Sailor Enceladus
Posts: 1543
Joined: Mon 22 Feb 2016, 19:43

#12 Post by Sailor Enceladus »

MochiMoppel: Haha yeah, it's pretty messed up, I had to compile file-5.27 from source to even see the "Opus audio" with file -b (older versions don't know what it is) and even then some oggs/ogas use weird things like x-flac+ogg (ogg containers for flac! wth) instead of audio_ogg like you said. I ended up just compiling MPlayer 1.3 from the source snapshot and now all that Opus stuff opens automatically without having to use a browser, working nice so far and beats awkward file manager exceptions! :lol:

scientist
Posts: 860
Joined: Sat 23 May 2015, 08:21

#13 Post by scientist »

Smithy wrote:Whilst people are talking about Rox, is it possible to make a progress display for files?
I have sat there waiting for the copy or move dialog box to close wondering if it has crashed when copying or moving a file (it never has crashed).

Here's an example of what I mean:
https://bash.cyberciti.biz/guide/A_prog ... uge_box%29

Maybe in a fetching green..
Thunar file manager has a progress display when moving or copying files.
Thanks,
Andy


Slacko 6.3.0 FULL INSTALL
JWM
File Manager - Thunar

User avatar
Smithy
Posts: 1151
Joined: Mon 12 Dec 2011, 11:17

#14 Post by Smithy »

Hi Scientist, I liked Thunar very much, but Rox filer seems to be the one the developers go with, so I was wondering about refinements in the woof git ce thing..
Another niggle was, I transferred 56gb recently, and Rox said there were three errors.
However, it did not say what three errors they were!
So at some point I might load up just an archive file that maybe corrupted!
Hey ho, three out of thousands 'aint bad, or whatever Meatloaf sang.

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

#15 Post by LazY Puppy »

Smithy wrote:Another niggle was, I transferred 56gb recently, and Rox said there were three errors.
However, it did not say what three errors they were!
Assuming those 56gb was a huge collection of files and not just a single one:

There should be a GUI while copying is executed and copied files are scrolling heavily in its window - dependent on the size of the files.

If the GUI doesn't quit and tells you of some errors, you can scroll the list manually to find out the errors.

Those 'copy-error-files' lines in the text field of the GUI will appear in red color.

Though it's a bit uncomfortable I must say...
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

#16 Post by MochiMoppel »

Smithy wrote:Whilst people are talking about Rox, is it possible to make a progress display for files?
Are you serious? ROX already has a progress bar and it works the same way as your linked script. The only difference: It doesn't print a percentage value. But when you see a progress bar that is 30% filled (see screenshot) it is fair to assume that you can do the
math and figure that 30% of files have been copied.
Smithy wrote:Another niggle was, I transferred 56gb recently, and Rox said there were three errors.
However, it did not say what three errors they were!
You have a hopelessly broken ROX or you didn't look close enough. When an error occurs ROX notes it in the transfer log , in red, preceeded with the word ERROR (e.g. ERROR: No such file or directory). When copying hundreds of files you may have to take the trouble and scroll back the log until you find the position in the chain where the error occurred. It's there. What else do you expect?
Attachments
ROX_progress_bar.png
(17.05 KiB) Downloaded 263 times

User avatar
Pete
Posts: 660
Joined: Sun 02 Mar 2014, 18:36

#17 Post by Pete »

It would be a right pain to scroll through a huge list in the case of 56GB worth of files.

Does ROX not write to some log file in which case a simple grep would make life much easier.

Code: Select all


cat /path/to/the/rox/log | grep "ERROR"


User avatar
Smithy
Posts: 1151
Joined: Mon 12 Dec 2011, 11:17

#18 Post by Smithy »

Confirmed, my Rox is broken, there is no progress bar. Will have to check when that got bust. (By me probably lol).

Yes there were three red flashes along the way, but I couldn't find the files and life moves on.

A lot of it is studio session mixes, but there might have been a non writeable sys file (3) snuck in there or something.

Suppose it might be an extreme case but possibly in the case of archiving, something that spits out the failures separately could be handy.

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

#19 Post by MochiMoppel »

Pete wrote:Does ROX not write to some log file
As you can see it does. It writes to the screen, puts it just in front of you, in case of errors doesn't close it so that you can examine it, makes it selectable so that you can select the whole log and copy it to a file for whatever purpose. Not enough? Then check the [X] Brief option. This will spare you the "pain" of scrolling or grepping through a list because it will log only the errors. If you are lucky the error log will reveal the name of the problem files, but don't count on that.
Smithy wrote:something that spits out the failures separately could be handy
Now we are going from "feature doesn't exist" to "feature could be better". OK, maybe. But first you should look at the options you already have before you ask for more. It is not hard to find errors, even in a long log. For the screenshot I copied 250 files, then maximized the copy log. Can you spot the error? I can :lol:
Attachments
ROX_copy_log.png
(135.89 KiB) Downloaded 183 times

Post Reply