Change default action of clicked files (SOLVED, so far)

For discussions about programming, programming questions/advice, and projects that don't really have anything to do with Puppy.
Post Reply
Message
Author
R-S-H
Posts: 487
Joined: Mon 18 Feb 2013, 12:47

Change default action of clicked files (SOLVED, so far)

#1 Post by R-S-H »

Hi.

I think anyone knows this:

- left-click onto a RoxApp directory runs the RoxApp
- left-click while pressing a shift key opens up the directory

- left-click onto a script executes the script
- left-click while pressing a shift key sends script to defaulttexteditor script

- left-click onto a jpg image sends the image to the image viewer
- left-click while pressing a shift key sends the image to... ... ...

... ... ...no, not to the image editor!

It sends the image to defaulttexteditor script also!

I want to change/modify this behavior.

So, where to do this?

Thanks

RSH
Last edited by R-S-H on Wed 21 Aug 2013, 13:23, edited 1 time in total.
[b][url=http://lazy-puppy.weebly.com]LazY Puppy Home
The new LazY Puppy Information Centre[/url][/b]

User avatar
Karl Godt
Posts: 4199
Joined: Sun 20 Jun 2010, 13:52
Location: Kiel,Germany

#2 Post by Karl Godt »

Openbox should have its configuration files somewhere ..

?

Icewm had them in /usr/share/*icewm?* or /usr/lib/*icewm?* I think ( Lupu-5.1.1 ) .

ROX-Filer :
User-definable shortcuts are disabled by default in Gtk2, and you have not enabled them. You can turn this feature on by:

1) using an XSettings manager, such as ROX-Session or gnome-settings-daemon, or

2) adding this line to ~/.gtkrc-2.0:
gtk-can-change-accels = 1
(this only works if NOT using XSETTINGS)
Hmm .. seems to be hardcoded ..?

User avatar
Karl Godt
Posts: 4199
Joined: Sun 20 Jun 2010, 13:52
Location: Kiel,Germany

#3 Post by Karl Godt »

/usr/local/apps/ROX-Filer/Help/Manual.html wrote:Left button click Open the file or directory clicked on. Hold down Control to select things instead of opening them. Hold down Shift to look inside applications, treat files as text, follow symlinks, or get more control over mount points (see Removable devices).

R-S-H
Posts: 487
Joined: Mon 18 Feb 2013, 12:47

#4 Post by R-S-H »

Thank you, Karl.

I've solved this using a sub-script (defaulttexteditor-bin) which is executed now by the defaulttexteditor script. In this sub-script I do check at first, if the submitted file or file list includes images (just checking for .png, .jpg, .bmp and .xpm at the moment)

If so, it will send the file/s to my defaultimageeditor script (gimp) - otherwise it will go to defaulttexteditor-bin (geany).

Works pretty good, so far.

RSH
[b][url=http://lazy-puppy.weebly.com]LazY Puppy Home
The new LazY Puppy Information Centre[/url][/b]

User avatar
Karl Godt
Posts: 4199
Joined: Sun 20 Jun 2010, 13:52
Location: Kiel,Germany

#5 Post by Karl Godt »

I am using similar for defaultmediaplayer with file command to send to gmplayer , gnome-mplayer , ffplay , vlc or gxine .

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

#6 Post by MochiMoppel »

Karl Godt wrote:I am using similar for defaultmediaplayer
I'm a bit lost here. I understand that R-S-H changed the defaulttexteditor script so that the script checks the file extensions (?) of the files passed to the script, then depending on file extension opens a suitable application. Is my assumption correct?

But what do you use for the defaultmediaplayer? If you Shift click a .mp3 file it's passed to defaulttexteditor, not defaultmediaplayer. Could you post an example?

User avatar
Karl Godt
Posts: 4199
Joined: Sun 20 Jun 2010, 13:52
Location: Kiel,Germany

#7 Post by Karl Godt »

Hey Moppel !

I am not using it for some ketzplank shortcut .

It's just for the
exec defaultmediaplayer "$@"
mime-type in /root/Choic/MIME-Types ie audio_mp4.

Hate shortcuts because it seems that every app uses its own syntax for shift and control and alt and that's too difficult for me to remember .

BTW must recognize, that in Precise 550 it is again "$1" instead of "$@" .. :evil:
Have not many files with spaces though .

User avatar
RSH
Posts: 2397
Joined: Mon 05 Sep 2011, 14:21
Location: Germany

#8 Post by RSH »

Hi.

Here are my scripts.

This one is the defaulttexteditor script.

Code: Select all

#!/bin/sh
exec /usr/local/bin/defaulttexteditor-bin "$@"
This one is the defaulttexteditor-bin script.

Code: Select all

#!/bin/sh
#------------------------------------------------------------------------------
# New BackEnd for the defaulttexteditor Script
# Check for image files first and send them to 'defaultimageeditor' Script
# when doing a left-click onto the image while holding a shift key down
#------------------------------------------------------------------------------

# Send submitted file name/s into a temp file
echo "$@" > /tmp/file_submitted_shift_key_holded_down

# Check for jpg, bmp, xpm and png files
# If submitted file is a image file (picture) send file to gimp
file_is_image="false"
if (grep '.png' /tmp/file_submitted_shift_key_holded_down) then
	exec /usr/local/bin/defaultimageeditor "$@"
	file_is_image="true"
	elif (grep '.PNG' /tmp/file_submitted_shift_key_holded_down) then
	exec /usr/local/bin/defaultimageeditor "$@"
	file_is_image="true"
	elif (grep '.jpg' /tmp/file_submitted_shift_key_holded_down) then
	exec /usr/local/bin/defaultimageeditor "$@"
	file_is_image="true"
	elif (grep '.JPG' /tmp/file_submitted_shift_key_holded_down) then
	exec /usr/local/bin/defaultimageeditor "$@"
	file_is_image="true"
	elif (grep '.bmp' /tmp/file_submitted_shift_key_holded_down) then
	exec /usr/local/bin/defaultimageeditor "$@"
	file_is_image="true"
	elif (grep '.BMP' /tmp/file_submitted_shift_key_holded_down) then
	exec /usr/local/bin/defaultimageeditor "$@"
	file_is_image="true"
	elif (grep '.xpm' /tmp/file_submitted_shift_key_holded_down) then
	exec /usr/local/bin/defaultimageeditor "$@"
	file_is_image="true"
	elif (grep '.XPM' /tmp/file_submitted_shift_key_holded_down) then
	exec /usr/local/bin/defaultimageeditor "$@"
	file_is_image="true"
	else
	file_is_image="false"
fi

# Else, submitted file is not a image file (picture) - so, send file to Geany
if [ "$file_is_image" = "false" ]; then
	exec geany "$@"
fi
Even though it works, I'm sure, real programmers would laugh on it and surely able to solve this using a three-lin-script (maybe?). :lol:

RSH
[b][url=http://lazy-puppy.weebly.com]LazY Puppy[/url][/b]
[b][url=http://rshs-dna.weebly.com]RSH's DNA[/url][/b]
[url=http://murga-linux.com/puppy/viewtopic.php?t=91422][b]SARA B.[/b][/url]

User avatar
Karl Godt
Posts: 4199
Joined: Sun 20 Jun 2010, 13:52
Location: Kiel,Germany

#9 Post by Karl Godt »

i would suggest to use -i --ignore-case option for grep .

Further : grep treats '.' as regular expression as any char placeholder by default. It needs to be escaped with blackslash to be interpreted as literal dot .
The use of '$' for last chars as regular expression might make sense too .

Example :

Code: Select all

grep -i '\.png$' /tmp/file_submitted_shift_key_holded_down
would grep anything that ends with .png or .PNG in that temporary file .

Another approach :

Code: Select all

SUFFIX=`echo "$@" | grep -oiE '\.png$|\.jpeg$|\.jpg$|\.ti[f]*$|\.bmp$|\.xpm$'`
case $SUFFIX in

.png|.PNG|.jpeg|.JPEG|.jpg|.JPG|.tiff|.TIFF|.bmp|.BMP|.xpm|.XPM)
file_is_image="likely_true"
exec defaultimageeditor "$@"
;;
*|'') 
file_is_image="likely_false"
file  "$@" | grep -iE 'script|text' && exec defaulttexteditor "$@"
;;

esac
NOTE : normally things are not executed in shell scripts after an exec shell builtin is triggered. Therefore file_is_image= assignment before exec line .
«Give me GUI or Death» -- I give you [[Xx]term[inal]] [[Cc]on[s][ole]] .
Macpup user since 2010 on full installations.
People who want problems with Puppy boot frugal :P

Post Reply