ROX: How to send files to Trash

How to do things, solutions, recipes, tutorials
Post Reply
Message
Author
User avatar
MochiMoppel
Posts: 2084
Joined: Wed 26 Jan 2011, 09:06
Location: Japan

ROX: How to send files to Trash

#1 Post by MochiMoppel »

Puppy's default deletion process (Ctrl+X) deletes files/folders permanently. The following keyboard shortcut (Ctrl+Shift+X) avoids the permanent deletion by sending files/folders to the Trash bin.

The shortcut doesn't use the clipboard, but uses xclip, which should be updated to handle non-ASCII filenames properly (see http://www.murga-linux.com/puppy/viewtopic.php?t=95018)

Step 1: Edit the file /root/.jwm/jwmrc-personal. Add the red lines:
[list]<Key mask="A" key="F1">root:3</Key>
<Key mask="A" key="F2">window</Key>

<Key mask="CS" key="x">exec:
FPATHS=\"$(xclip -o|sed 's/[ ]*$//;s_ /_" "/_g')\"
FCOUNT=$(echo "$FPATHS" | awk -F"\"/" '{print NF-1}'); ((FCOUNT))|| exit
Xdialog --yesno "Send $FCOUNT file(s) to the Trash Bin?" 0 0 || exit
eval /usr/local/apps/Trash/AppRun $FPATHS
</Key>
[/list]Step 2: Restart JWM
Attachments
SendToTrash.png
Select files and press Ctrl+Shift+X
(96.77 KiB) Downloaded 618 times

User avatar
Flash
Official Dog Handler
Posts: 13071
Joined: Wed 04 May 2005, 16:04
Location: Arizona USA

#2 Post by Flash »

How hard do you think would it be to incorporate this into Copy Fast? Would it even be worth doing?

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

#3 Post by MochiMoppel »

This would be for don570 to decide, but I can't see why you would want to integrate it. CopyFast has a very limited scope (copies exactly 1 file/folder to 1 destination), and for that it uses a huge code overhead. If you want to use the context menu (as CopyFast does) there are much, much easier solutions.

User avatar
nic007
Posts: 3408
Joined: Sun 13 Nov 2011, 12:31
Location: Cradle of Humankind

#4 Post by nic007 »

Good but giving a choice to send to trash or delete permanently in the first place would be even better. Can this be done as it will be an improvement on the ways linux and windows do things by default? I have trash in my "open with" menu which should actually be "send to" for this purpose. I suppose your workaround only applies for keyboard usage?

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

#5 Post by MochiMoppel »

nic007 wrote:Good but giving a choice to send to trash or delete permanently in the first place would be even better. Can this be done as it will be an improvement on the ways linux and windows do things by default?
Yes, but my intention was to keep the code as simple a possible. This way it can be used as a template for any script/shortcut that needs a list of files selected in ROX as input.
I suppose your workaround only applies for keyboard usage?
I don't see it as a "workaround" and keyboard shortcut is only one possible usage. If you like you can turn it into a desktop button or whatever you fancy.

User avatar
nic007
Posts: 3408
Joined: Sun 13 Nov 2011, 12:31
Location: Cradle of Humankind

#6 Post by nic007 »

So, how about giving a choice for starters (permanent delete or send to trash). Any ideas?

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

#7 Post by MochiMoppel »

nic007 wrote:So, how about giving a choice for starters (permanent delete or send to trash). Any ideas?
How about this?

Code: Select all

<Key mask="CS" key="x">	exec:
	FPATHS="$(xclip -o|sed 's/[ ]*$//;s_ /_" "/_g')"
	FCOUNT=$(echo "$FPATHS" | awk -F""/" '{print NF-1}'); ((FCOUNT))|| exit
	ANSWER=$(gxmessage -bg "#008080" -fg white -fn "bold 12" -center -print -buttons "Delete permanently":0,"Send to Trash":1,"Cancel":2 -default "Send to Trash" $'\n\t\t\tDelete '$FCOUNT' file(s) ?')
	case $ANSWER in
	  "Delete permanently") ERR=$(eval rm -fr $FPATHS 2>&1) ;;
	  "Send to Trash"     ) eval /usr/local/apps/Trash/AppRun $FPATHS ;;
	esac
	[ "$ERR" ] && gxmessage -name "Ups, smells like error" -bg red -fg white -center -buttons "OK":0 -default "OK" "$ERR"
</Key>
When deleting permanently, the script traps errors and shows a dialog with error messages. Doing the same for "Send to Trash" would be possible, but not practical: As if it where not enough to play an annoying barking sound whenever sending something to trash, the application also sends a bogus error message (translating into "I have just barked!"), which would turn such approach into an additional annoyance :cry:
Attachments
Trash_Delete_Shortcut.png
(74.19 KiB) Downloaded 478 times

User avatar
nic007
Posts: 3408
Joined: Sun 13 Nov 2011, 12:31
Location: Cradle of Humankind

#8 Post by nic007 »

MochiMoppel wrote:
nic007 wrote:So, how about giving a choice for starters (permanent delete or send to trash). Any ideas?
How about this?

Code: Select all

<Key mask="CS" key="x">	exec:
	FPATHS="$(xclip -o|sed 's/[ ]*$//;s_ /_" "/_g')"
	FCOUNT=$(echo "$FPATHS" | awk -F""/" '{print NF-1}'); ((FCOUNT))|| exit
	ANSWER=$(gxmessage -bg "#008080" -fg white -fn "bold 12" -center -print -buttons "Delete permanently":0,"Send to Trash":1,"Cancel":2 -default "Send to Trash" $'\n\t\t\tDelete '$FCOUNT' file(s) ?')
	case $ANSWER in
	  "Delete permanently") ERR=$(eval rm -fr $FPATHS 2>&1) ;;
	  "Send to Trash"     ) eval /usr/local/apps/Trash/AppRun $FPATHS ;;
	esac
	[ "$ERR" ] && gxmessage -name "Ups, smells like error" -bg red -fg white -center -buttons "OK":0 -default "OK" "$ERR"
</Key>
When deleting permanently, the script traps errors and shows a dialog with error messages. Doing the same for "Send to Trash" would be possible, but not practical: As if it where not enough to play an annoying barking sound whenever sending something to trash, the application also sends a bogus error message (translating into "I have just barked!"), which would turn such approach into an additional annoyance :cry:
Tried this with Puppy 412. Can't see the top message (eg, delete these 2 files?)

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

#9 Post by musher0 »

Hello MochiMoppei, nic007 and all.

Here is an adaptation of the above for pekwm.

I've made Mochi's original into a separate script, which is called, AFTER
THE FILE HAS BEEN HIGHLIGHTED, by the key combo Ctrl-Shift-x.

Simply copy and paste the line at the bottom of this script, the one start-
ing with the word "Keypress", in pekwm's < keys > file after line 78 or so
in section "External Commands". Then restart pekwm for it to take effect.

~~~

The advantage of having it as a separate script is that you can also make
symbolic links of it:
-- in the general SendTo directory, and / or
-- in a sub-directory for a particular file type of SendTo.
In this case, again, you highlight the file to delete, but you click on the
symbolic link in the right-click menu of the ROX-Filer.

As Mochi mentioned above, it will also work if you put an icon of this
script on your desktop. In this case, you highlight the file you wish to
delete, as in the above procedures, and you click on the desktop icon.

~~~

Please note that this script is an add-on to BarryK's Trash ROX-App at
/usr/local/apps/Trash. It won't work without it -- to state the obvious!

~~~

Before you ask: the explanations above are the translation of the
comments in French in the script below.

~~~

Any feedback or suggestions for improvement welcome. TIA.
If comments are positive I will make a pet archive of this.

~~~

Last but not least: many thanks to MochiMoppei for his initial idea/insight.

BFN.

~~~~~~~

Code: Select all

#!/bin/sh
# /usr/local/bin/DelPermOrTrash.sh
#
# Requis : l'appli ROX de BarryK à /usr/local/apps/Trash.
# Required: BarryK's Trash ROX-App at /usr/local/apps/Trash.
#
# Dérivé de : MochiMoppei,
# http://www.murga-linux.com/puppy/viewtopic.php?p=792936&sort=lastpost#792936
#
# Adapté pour pekwm 'keys' (voir au bas du script) par musher0, 5 déc. 2016.
#
# Comment faire
# -=> On doit d'abord surligner le fichier. <=-
# ==============================================
# Si on a surligné le fichier, cette astuce peut s'utiliser, non seulement
# avec la combinaison de touches Ctrl-Motion-x dans pekwm,
# mais aussi
# à partir d'une icône sur le bureau OU
# de liens symb. dans
# -- le répertoire SendTo correpondant au type de fichier OU
# -- le répertoire SendTo général.
####
FPATHS=\"$(xclip -o|sed 's/[ ]*$//;s_ /_" "/_g')\"
FCOUNT=$(echo "$FPATHS" | awk -F"\"/" '{print NF-1}'); ((FCOUNT))|| exit
ANSWER=$(gxmessage -bg "#008080" -fg white -fn "bold 12" -center -print -buttons "Delete permanently":0,"Send to Trash":1,"Cancel":2 -default "Send to Trash" $'\n\t\t\tDelete '$FCOUNT' file(s) ?')

case $ANSWER in
	"Delete permanently") ERR=$(eval rm -fr $FPATHS 2>&1) ;;
	"Send to Trash"     ) eval /usr/local/apps/Trash/AppRun $FPATHS ;;
esac
[ "$ERR" ] && gxmessage -name "Ups, smells like error" -bg red -fg white -center -buttons "OK":0 -default "OK" "$ERR"

#############################################
# Entrée dans le fichier keys de pekwm :
# Keypress = "Ctrl Shift x" { Actions = "Exec /usr/local/bin/DelPermOrTrash.sh &" }
# Copier-coller après la ligne 78, dans la section "External Commands".
#############################################
musher0
~~~~~~~~~~
"You want it darker? We kill the flame." (L. Cohen)

Post Reply