Puppy Linux Discussion Forum Forum Index Puppy Linux Discussion Forum
Puppy HOME page : puppylinux.com
"THE" alternative forum : puppylinux.info
 
 FAQFAQ   SearchSearch   MemberlistMemberlist   UsergroupsUsergroups   RegisterRegister 
 ProfileProfile   Log in to check your private messagesLog in to check your private messages   Log inLog in 

The time now is Thu 23 Oct 2014, 03:00
All times are UTC - 4
 Forum index » Off-Topic Area » Programming
How to add an option to ROX' right-click menu?
Post new topic   Reply to topic View previous topic :: View next topic
Page 1 of 2 [18 Posts]   Goto page: 1, 2 Next
Author Message
DaveS


Joined: 09 Oct 2008
Posts: 3726
Location: UK

PostPosted: Mon 10 Jan 2011, 15:28    Post subject:  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!
Back to top
View user's profile Send private message 
Flash
Official Dog Handler


Joined: 04 May 2005
Posts: 11120
Location: Arizona USA

PostPosted: Mon 10 Jan 2011, 15:48    Post subject:  

Have you considered modifying the "Delete" option in ROX's right-click menu, so it moves the highlighted item(s) to the trash rather than deleting them?
Back to top
View user's profile Send private message 
technosaurus


Joined: 18 May 2008
Posts: 4353

PostPosted: Mon 10 Jan 2011, 16:00    Post subject:  

name this script as "trash" and put it in or make a symlink in the sendto (or "open with") directory
Code:
#!/bin/sh
[ ! -d $HOME/Trash ] && mkdir $HOME/Trash
mv $@ $HOME/Trash


(It doesn't remember where they came from though for "undelete")

_________________
Web Programming - Pet Packaging 100 & 101
Back to top
View user's profile Send private message 
DaveS


Joined: 09 Oct 2008
Posts: 3726
Location: UK

PostPosted: Mon 10 Jan 2011, 16:16    Post subject:  

Flash wrote:
Have you considered modifying the "Delete" option in ROX's right-click menu, so it moves the highlighted item(s) to the trash rather than deleting them?


Thanks Flash, I will look at that script and see what I can learn.

_________________
Spup Frugal HD and USB
Root forever!
Back to top
View user's profile Send private message 
DaveS


Joined: 09 Oct 2008
Posts: 3726
Location: UK

PostPosted: Mon 10 Jan 2011, 16:19    Post subject:  

technosaurus wrote:
name this script as "trash" and put it in or make a symlink in the sendto (or "open with") directory
Code:
#!/bin/sh
[ ! -d $HOME/Trash ] && mkdir $HOME/Trash
mv $@ $HOME/Trash


(It doesn't remember where they came from though for "undelete")


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.
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!
Back to top
View user's profile Send private message 
DaveS


Joined: 09 Oct 2008
Posts: 3726
Location: UK

PostPosted: Mon 10 Jan 2011, 17:14    Post subject:  

OK, so
Code:
[ ! -d $HOME/Trash ] && mkdir $HOME/Trash
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.
Code:
mv $@ $HOME/Trash
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?
_________________
Spup Frugal HD and USB
Root forever!
Back to top
View user's profile Send private message 
technosaurus


Joined: 18 May 2008
Posts: 4353

PostPosted: Mon 10 Jan 2011, 17:26    Post subject:  

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

_________________
Web Programming - Pet Packaging 100 & 101
Back to top
View user's profile Send private message 
DaveS


Joined: 09 Oct 2008
Posts: 3726
Location: UK

PostPosted: Mon 10 Jan 2011, 17:31    Post subject:  

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


OK thanks. I need a little time to digest and experiment with this.

_________________
Spup Frugal HD and USB
Root forever!
Back to top
View user's profile Send private message 
Béèm


Joined: 21 Nov 2006
Posts: 11782
Location: Brussels IBM Thinkpad R40, 256MB, 20GB, WiFi ipw2100. Frugal Lin'N'Win

PostPosted: Mon 10 Jan 2011, 17:43    Post subject:  

technosaurus wrote:
name this script as "trash" and put it in or make a symlink in the sendto (or "open with") directory
Code:
#!/bin/sh
[ ! -d $HOME/Trash ] && mkdir $HOME/Trash
mv $@ $HOME/Trash


(It doesn't remember where they came from though for "undelete")
Interesting.
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
Back to top
View user's profile Send private message 
Béèm


Joined: 21 Nov 2006
Posts: 11782
Location: Brussels IBM Thinkpad R40, 256MB, 20GB, WiFi ipw2100. Frugal Lin'N'Win

PostPosted: Mon 10 Jan 2011, 17:48    Post subject:  

As far as I understand it, if you execute set in a terminal, you will find in the list of system variables
Code:
HOME=/root

If you want to use that variable in a script it is to be preceded by $

_________________
Time savers:
Find packages in a snap and install using Puppy Package Manager (Menu).
Consult Wikka
Use peppyy's puppysearch
Back to top
View user's profile Send private message 
technosaurus


Joined: 18 May 2008
Posts: 4353

PostPosted: Mon 10 Jan 2011, 18:10    Post subject:  

Béèm wrote:
May I ask what the purpose of && is?

it is just a shortened if-then

[ <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 ~ )

_________________
Web Programming - Pet Packaging 100 & 101
Back to top
View user's profile Send private message 
DaveS


Joined: 09 Oct 2008
Posts: 3726
Location: UK

PostPosted: Mon 10 Jan 2011, 18:13    Post subject:  

Hmmm... this is becoming a valuable thread. Bookmarked.
_________________
Spup Frugal HD and USB
Root forever!
Back to top
View user's profile Send private message 
technosaurus


Joined: 18 May 2008
Posts: 4353

PostPosted: Mon 10 Jan 2011, 18:32    Post subject:  

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

_________________
Web Programming - Pet Packaging 100 & 101
Back to top
View user's profile Send private message 
Béèm


Joined: 21 Nov 2006
Posts: 11782
Location: Brussels IBM Thinkpad R40, 256MB, 20GB, WiFi ipw2100. Frugal Lin'N'Win

PostPosted: Mon 10 Jan 2011, 19:17    Post subject:  

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.

_________________
Time savers:
Find packages in a snap and install using Puppy Package Manager (Menu).
Consult Wikka
Use peppyy's puppysearch
Back to top
View user's profile Send private message 
Karl Godt


Joined: 20 Jun 2010
Posts: 3972
Location: Kiel,Germany

PostPosted: Mon 10 Jan 2011, 19:26    Post subject:  

does `mv $@` also works with spaces in the filename

and wouid `mv "$@"` also work ?
Back to top
View user's profile Send private message Visit poster's website 
Display posts from previous:   Sort by:   
Page 1 of 2 [18 Posts]   Goto page: 1, 2 Next
Post new topic   Reply to topic View previous topic :: View next topic
 Forum index » Off-Topic Area » Programming
Jump to:  

You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum
You cannot attach files in this forum
You can download files in this forum


Powered by phpBB © 2001, 2005 phpBB Group
[ Time: 0.0982s ][ Queries: 12 (0.0135s) ][ GZIP on ]