How to add an option to ROX' right-click menu?
How to add an option to ROX' right-click menu?
How would I form a script that appeared in the rox right click menu adding an option to move the highlighted file to the trash?
Spup Frugal HD and USB
Root forever!
Root forever!
- technosaurus
- Posts: 4853
- Joined: Mon 19 May 2008, 01:24
- Location: Blue Springs, MO
- Contact:
name this script as "trash" and put it in or make a symlink in the sendto (or "open with") directory
(It doesn't remember where they came from though for "undelete")
Code: Select all
#!/bin/sh
[ ! -d $HOME/Trash ] && mkdir $HOME/Trash
mv $@ $HOME/Trash
Check out my [url=https://github.com/technosaurus]github repositories[/url]. I may eventually get around to updating my [url=http://bashismal.blogspot.com]blogspot[/url].
Thanks Technosaurus. A ready made solution. I will try to figure out how it works so I can use the elements again. Undelete does not matter. I guess I never even considered it an option.technosaurus wrote:name this script as "trash" and put it in or make a symlink in the sendto (or "open with") directory(It doesn't remember where they came from though for "undelete")Code: Select all
#!/bin/sh [ ! -d $HOME/Trash ] && mkdir $HOME/Trash mv $@ $HOME/Trash
I figured out a script to transfer mp3 downloads to my player but could not get this one.
Spup Frugal HD and USB
Root forever!
Root forever!
OK, so looks for a folder called Trash and if it does not find it creates it. Cool. I know this because the code contains a 'teaching bomb', the actual directory in Puppy is called .Trash, so it made me another called Trash and moved the file there.
is the bit that does the work then I guess. mv is straightforward, I guess $@ means 'currently selected file', HOME/Trash is straightforward but what does the leading $ sign in front of HOME/Trash tell it to do?
Code: Select all
[ ! -d $HOME/Trash ] && mkdir $HOME/Trash
Code: Select all
mv $@ $HOME/Trash
Spup Frugal HD and USB
Root forever!
Root forever!
- technosaurus
- Posts: 4853
- Joined: Mon 19 May 2008, 01:24
- Location: Blue Springs, MO
- Contact:
the . before Trash will make it a hidden folder though - if that's what you want
$@ is all selected files
$1 is the first selected file ... $2 and so on
$HOME is an environment variable that is exported by /etc/profile during startup ... for other (non-root) systems it would be /home/user
to see a complete list of environment variables enter this at a prompt:
env
the "$" just means it is a variable
others:
$# is the number of parameters passed to the script
$! is the pid of the last command
(there are a bunch of useful variables)
[ -d something ] returns true if something is a directory
the ! means not - so it returns true only if it is not a directory
the && afterward only executes if the preceding returns true
$@ is all selected files
$1 is the first selected file ... $2 and so on
$HOME is an environment variable that is exported by /etc/profile during startup ... for other (non-root) systems it would be /home/user
to see a complete list of environment variables enter this at a prompt:
env
the "$" just means it is a variable
others:
$# is the number of parameters passed to the script
$! is the pid of the last command
(there are a bunch of useful variables)
[ -d something ] returns true if something is a directory
the ! means not - so it returns true only if it is not a directory
the && afterward only executes if the preceding returns true
Check out my [url=https://github.com/technosaurus]github repositories[/url]. I may eventually get around to updating my [url=http://bashismal.blogspot.com]blogspot[/url].
OK thanks. I need a little time to digest and experiment with this.technosaurus wrote:the . before Trash will make it a hidden folder though - if that's what you want
$@ is all selected files
$1 is the first selected file ... $2 and so on
$HOME is an environment variable that is exported by /etc/profile during startup ... for other (non-root) systems it would be /home/user
to see a complete list of environment variables enter this at a prompt:
env
the "$" just means it is a variable
others:
$# is the number of parameters passed to the script
$! is the pid of the last command
(there are a bunch of useful variables)
[ -d something ] returns true if something is a directory
the ! means not - so it returns true only if it is not a directory
the && afterward only executes if the preceding returns true
Spup Frugal HD and USB
Root forever!
Root forever!
- Béèm
- Posts: 11763
- Joined: Wed 22 Nov 2006, 00:47
- Location: Brussels IBM Thinkpad R40, 256MB, 20GB, WiFi ipw2100. Frugal Lin'N'Win
Interesting.technosaurus wrote:name this script as "trash" and put it in or make a symlink in the sendto (or "open with") directory(It doesn't remember where they came from though for "undelete")Code: Select all
#!/bin/sh [ ! -d $HOME/Trash ] && mkdir $HOME/Trash mv $@ $HOME/Trash
May I ask what the purpose of && is?
Time savers:
Find packages in a snap and install using Puppy Package Manager (Menu).
Consult Wikka
Use peppyy's puppysearch
Find packages in a snap and install using Puppy Package Manager (Menu).
Consult Wikka
Use peppyy's puppysearch
- Béèm
- Posts: 11763
- Joined: Wed 22 Nov 2006, 00:47
- Location: Brussels IBM Thinkpad R40, 256MB, 20GB, WiFi ipw2100. Frugal Lin'N'Win
As far as I understand it, if you execute set in a terminal, you will find in the list of system variables
If you want to use that variable in a script it is to be preceded by $
Code: Select all
HOME=/root
Time savers:
Find packages in a snap and install using Puppy Package Manager (Menu).
Consult Wikka
Use peppyy's puppysearch
Find packages in a snap and install using Puppy Package Manager (Menu).
Consult Wikka
Use peppyy's puppysearch
- technosaurus
- Posts: 4853
- Joined: Mon 19 May 2008, 01:24
- Location: Blue Springs, MO
- Contact:
it is just a shortened if-thenBéèm wrote:May I ask what the purpose of && is?
[ <something2check> ] && do_a || do_b
if <something2check> evaluates as true then do_a else do_b
the great part is that it doesn't need to be a comparison like <, >, -lt, -gt, ==, !, -n, -x ... it can be a "`command`" (if the command completes "succesfully" it evaluates as true - user selects ok instead of cancel or closing a dialog for example)
btw set works differently with different shells and can have parameters like -a ... export HOME=/notroot should sufficiently break anything that is looking for the real home (also a common shortcut for $HOME is ~ )
Check out my [url=https://github.com/technosaurus]github repositories[/url]. I may eventually get around to updating my [url=http://bashismal.blogspot.com]blogspot[/url].
- technosaurus
- Posts: 4853
- Joined: Mon 19 May 2008, 01:24
- Location: Blue Springs, MO
- Contact:
We kinda got off of the original topic, but still usefull for implementing it I guess - more bash scripting techniques are available here:
http://tldp.org/LDP/abs/html/
but is significantly enhanced if you can master sed and awk
http://www.grymoire.com/Unix/Sed.html
http://www.grymoire.com/Unix/Awk.html
and a basic user interface with Xdialog: (not great but most distros at least have it installed by default)
http://xdialog.free.fr/doc/index.html
http://tldp.org/LDP/abs/html/
but is significantly enhanced if you can master sed and awk
http://www.grymoire.com/Unix/Sed.html
http://www.grymoire.com/Unix/Awk.html
and a basic user interface with Xdialog: (not great but most distros at least have it installed by default)
http://xdialog.free.fr/doc/index.html
Check out my [url=https://github.com/technosaurus]github repositories[/url]. I may eventually get around to updating my [url=http://bashismal.blogspot.com]blogspot[/url].
- Béèm
- Posts: 11763
- Joined: Wed 22 Nov 2006, 00:47
- Location: Brussels IBM Thinkpad R40, 256MB, 20GB, WiFi ipw2100. Frugal Lin'N'Win
Thank you Technosaurus.
I saw the difference between set and env.
Bookmarked also.
Specially the part to test if a directory exist is of interest as I have been trying code, which never worked and in fact it's simple.
I saw the difference between set and env.
Bookmarked also.
Specially the part to test if a directory exist is of interest as I have been trying code, which never worked and in fact it's simple.
Time savers:
Find packages in a snap and install using Puppy Package Manager (Menu).
Consult Wikka
Use peppyy's puppysearch
Find packages in a snap and install using Puppy Package Manager (Menu).
Consult Wikka
Use peppyy's puppysearch
- ravensrest
- Posts: 365
- Joined: Fri 22 Feb 2008, 16:43
- Location: Grants Pass, Oregon
Putting a symlink to your "Trash" script in ~/.config/rox.sourceforge.net/OpenWith will result in the Trash item showing up in the Open With... item whenever you right click in Rox-filer. You can instead make the Trash script show up at the top of the main Rox-filer right click menu by selecting the Customize Menu... from the Rox-filer menu that pops up when an item is right clicked. The SendTo directory that pops up is symlinked to the OpenWith directory. Create a symlink in this way for each type of file you want to be able to move to the trash bin. See the rox manual in Puppy for more information.
BS
BS
- technosaurus
- Posts: 4853
- Joined: Mon 19 May 2008, 01:24
- Location: Blue Springs, MO
- Contact:
Try it and see - $@ should work with dragged files but not with command line entry unless you enclose spaced files with quotes -- I have a snippet that replaces spaces thoughKarl Godt wrote:does `mv $@` also works with spaces in the filename
and wouid `mv "$@"` also work ?
Code: Select all
#!/bin/sh
[ $1 ] && cd $1
for x in *;do
y=`echo $x |sed "s/ /_/g"`;
[ "$x" != "$y" ] && mv "$x" "$y" && [ -d "$y" ] && $0 $y || [ -d "$x" ] && $0 $x;
done
if you entered a directory as input change to that directory
for all files/directories in the current directory do
set up a variable to compare to x try to replace space with underscore using sed
if the variables don't match then must have had a spaces so rename (move) that file to the string with underscores
if the current y or x is a directory run this script in that directory too (this is recursion)
done
$0 refers to the script itself so you can call it recursively as above regardless if it is in $PATH or what it is named ... you can make a self destructing script like:
rm -f $0
Check out my [url=https://github.com/technosaurus]github repositories[/url]. I may eventually get around to updating my [url=http://bashismal.blogspot.com]blogspot[/url].
just to add something that already exists is easy
as explained with symlinks
---------------------------------------------------------------------
*but if you truly want to add a new app to rox that you made its more complex and more code to take care of all of the steps needed
this not only automates it for you it shows you step by step how its done
here is a script you could easily modify to build any right click app
It already works for the trash as is so you have a working example to start with
how to
unzip these two files to root
/root/dnd_trash
/root/setup-global-trash
then just a one time set up needed click on this file and you are done you never have to do that part again
root/setup-global-trash
it uses the trash bin
and a new app dir was created
and a bonus dragNdrop selected files are move to trash
you get a prompt if you want to move the file as a safety
this is how I auto build app directories when I need one
Joe
as explained with symlinks
---------------------------------------------------------------------
*but if you truly want to add a new app to rox that you made its more complex and more code to take care of all of the steps needed
this not only automates it for you it shows you step by step how its done
here is a script you could easily modify to build any right click app
It already works for the trash as is so you have a working example to start with
how to
unzip these two files to root
/root/dnd_trash
/root/setup-global-trash
then just a one time set up needed click on this file and you are done you never have to do that part again
root/setup-global-trash
it uses the trash bin
and a new app dir was created
and a bonus dragNdrop selected files are move to trash
you get a prompt if you want to move the file as a safety
this is how I auto build app directories when I need one
Joe
- Attachments
-
- trash.png
- (15.22 KiB) Downloaded 513 times
-
- dnd_trash-1-i486-3_SLXR.tar.gz
- (1.92 KiB) Downloaded 328 times