Hi,
I'm don't sure if this is a right place to post this.
Is it possible to add commands to the context menu when you right click the desktop?
e.g Shutdown option
is there a file that i could edit to do this ?
Thank you
Hi,
I'm don't sure if this is a right place to post this.
Is it possible to add commands to the context menu when you right click the desktop?
e.g Shutdown option
is there a file that i could edit to do this ?
Thank you
Write a given command into an empty pluma text file and save it as "name.sh" (where "name" is some name you have given it that identifies the command contained in the file on some meaningful way). You need to save the file to /home/username/.config/caja/scripts (where "username" is your own username)
You will notice that the ".config" part of that save-path has a "." just in front of it. This means it is a hidden folder. So, when you save your file, you will need to ensure that all hidden files and folders are visible in the save dialog box in order for you to be able to navigate to the correct folder. See below:
Once you have saved it. Close pluma, open your home folder in caja and press CTRL/h and this will display your hidden files and folders. Navigate to your file contained in the /home/username/.config/caja/scripts folder. Once there, right-click the file and choose "properties". Then, choose the "permissions" tab and check the "allow executing file as program" checkbox. See below:
Then close the "properties" dialog box and close caja so that you are back at the desktop.
If you now right-click to bring up your context menu you will notice that there is a new item displayed called "scripts". If you go into the "scripts" sub-menu you will see your newly created file and, if you select that file, your command will execute.
I should also say, you are able to create sub-folders in the scripts folder and place your various scripts in the sub-folders. That way, if you end up creating a large number of useful scripts, you don’t have to have them all in a single big column in the context-menu scripts folder. In other words, you can organize them according to their function. See below:
However, there is one caveat to the above. If your command contains the "sudo" sub-command, then it would, all other things being equal, require that you enter your login password in order for the command to execute. This is fine if you are executing your command inside a terminal, since it gives you the opportunity to enter your password. However, by executing it from the context menu, you are not given this opportunity. In which case, the command will simply not execute.
I am about to show you a method for getting around the requirement for a sudo password, in turn allowing commands to be successfully executed from the caja-script context menu even if they contain a sudo sub-command inside them.
The following steps show how to disable the sudo password prompt, thus rendering you no longer required to enter it,
Be warned, though. Disabling your sudo password requires that you edit a very important file called the “sudoer” file and if you screw up while you are editing it, you can knacker your entire system and you will have to re-write it. I know this because I have done precisely that myself on a previous occasion. Furthermore, disabling your sudo passsword prompt is viewed by some as leaving your system less secure. However, I am less personally concerned about this than others and so I have no problem with disabling it. It's a matter of taste and risk-tolerance I guess. In any event, you still have to enter your password at boot-up.
Open up a terminal. Type “sudo visudo” and press the “Enter” key. After typing in your password at the prompt, press “Enter”. You will be taken into something called the “sudoer” file.
Hold the down arrow key and you will see the cursor move to the bottom of the file. Paste the following line below all other lines (in order to paste using only the keyboard in a terminal, you need to press the CTRL/SHIFT/V keys simultaneously):
yourusername ALL=NOPASSWD: ALL
where “yourusername” should be replaced with your actual user-name (mine, for example, is “stephen”)
a) press CTRL and X
b) You will be prompted to type Y or N in order to save or discard the modifications. You must type Type Y
c) You will be given another prompt for the name that is given. Simply press the “Enter” key.
You should now find you have dropped out of the sudoer file and are back at the normal terminal prompt. That's it, you can close the terminal at that point. From now on, any time you would normally be asked for your password in a terminal, you now won't be.
I have noticed that the above procedure seems to have the effect of requiring you to enter fewer passwords on the main GUI desktop as well. But you are still asked for them sometimes when doing things like system management stuff (installing certain software in the software centre or opening synaptic, etc).
P.S.
I've just had a hunt about on the Ubuntu forums and the commands for shutting down/restarting your system are:
sudo shutdown -r now = to reboot the system
sudo shutdown -h now = to close the system
sudo halt -p = to shut and turnoff the system
sudo halt = to close the system
sudo reboot = to reboot the system
You could test these from a terminal first to see how they work and what, if any, differences there are between them. My guess is the first two will be best suited to your needs.
Thank you Steve,
i’ll try that
Is there a chance to pass path to file/files that i open context menu on into a script?
Hi Steve
Thank you so much for taking the time and explaining this. I had already spent half a day trying to work it out and then I found your post. I very much aprreciate what you have written here and the time that you have taken to post this (even with pictures). Thank you so much. 10/10 VG :¬) Joe
I have everything working as you described - thank you
HOWEVER I have a strange problem.
If I write a short script (called ZAP) with the following line in…
leafpad $CAJA_SCRIPT_SELECTED_URIS
and I right-click the file, choose scripts, then chose ZAP - this file opens with leafpad.
GREAT!
HOWEVER
If I write a short script (called ZAP) with the following line in…
rm $CAJA_SCRIPT_SELECTED_URIS
and I right-click the file, choose scripts, then chose ZAP - the file should delete but NOTHING HAPPENS.
Any Ideas thanx
I am not sure what is wrong with the script. but, it occurs to me you don't need an independently written script to remove a file since the option is already built into your context menu to remove a file. See below:
Thanx again Steve - you are a wizard.
I only use the command rm as an example.
I really wish to use SHRED - perhaps I should have stated this in my problem.
Thanx a lot
JE
I have had a hunt around and have found a script that employs the shred command on a selected file. See below:
#!/usr/bin/env bash
nfiles="$#"
files=""
for file in "$@" ; do
if [ ${#files} -gt 0 ] ; then files="$files\n"; fi
files=$files$(basename "$file")
done
zenity --question --title="shred these $nfiles files - REALLY??" --text="$files"
if [ "$?" = 1 ] ; then
exit $?
else
nfile=0
(for file in "$@" ; do
echo \# shredding $(basename "$file")...
shredout=$(shred -u -z -n 1 "$file" 2>&1)
rc=$?
if [ $rc -ne 0 ] ; then
echo "100"
zenity --error --title="No break for you today" --text="$shredout"
exit $rc
else
let nfile++
echo $((nfile * 100 / nfiles))
fi
done ) | zenity --progress --title="Wiping files..." --auto-close \
--percentage=0 --text="starting..." --no-cancel
fi
exit 0
Paste the above into a Pluma file. Save as a bash script and place in your .config/caja/scripts folder. I have just tested it and it appears to work. That is to say, after applying this shred script to a selected file, I checked in my wastebasket and it was not there.
My apologizes Joe and Steve
A slip of the mouse on my part turned this thread into a private topic.
It wont happen again. I promise
Fantastic. You are a Wizard sir.
This works perfectly.
Thank you ever so much.
Joe.
No problem at all v3xx, no problem at all