[SOLVED] Script not working in caja

Forum rules
Before you post please read this

[SOLVED] Script not working in caja

Postby jibe on Fri Jun 13, 2014 3:12 am

Hi,

I have this very simple script :
Code: Select all
#!/bin/sh
gpg -d $1 >${1%.*}

It's working well in a terminal or a console, but when I use it as a caja script, it gives me an empty file ! Why ?

Another question : Where must I put a caja script so that it can be used by any user ?

thks
Last edited by jibe on Sat Jun 14, 2014 5:42 am, edited 1 time in total.
User avatar
jibe
Level 3
Level 3
 
Posts: 102
Joined: Thu Dec 28, 2006 4:31 pm

Linux Mint is funded by ads and donations.
 

Re: Script not working in caja

Postby jibe on Fri Jun 13, 2014 3:59 am

Something that could be a reason :

gpg is asking me the passphrase the first time I use it, and never after until I close my session and open a new one. So I didn't noticed anything wrong with my caja script.

But I just see that even when I just started the session, the script doesn't ask the passphrase when it's used as a caja script. Surely, without the passphrase, it cannot decode and generates an empty file ! But

1 - Is it also the reason when the passphrase has already been given and the script executed out of caja doesn't asks it, but decodes well the file ?

2 - How to do to have some script decoding gpg coded files ?

Thanks.
User avatar
jibe
Level 3
Level 3
 
Posts: 102
Joined: Thu Dec 28, 2006 4:31 pm

Re: Script not working in caja

Postby eanfrid on Fri Jun 13, 2014 5:14 am

1/ caja scripts must use special and dedicated environment variables
2/ those scripts (or a symlink to) must be stored in ~/.config/caja/scripts to make them available with a right-click on a file/folder
690563f5f46fa7.png

3/ when opening this folder in caja, a dialog box will be displayed; for instance (in french):
46579276418d24.png

4/ use is explained in caja help about scripts
5/ my method for system-wide scripts is to store them into a folder under /usr/local/bin/caja_scripts and make a symlink to them in ~/.config/caja/scripts

one easy example:
Code: Select all
#!/bin/sh
FILE=$(echo "$CAJA_SCRIPT_SELECTED_FILE_PATHS")
eiciel "$FILE"
exit
Main desktop: Debian GNU/Linux Wheezy 64bit w/custom 3.14 longterm kernel - MATE 1.8.1
(i5 2400@3.7GHz - 16GB DDR3 - HD6770 w/radeon driver - SSD+RAID1)
User avatar
eanfrid
Level 7
Level 7
 
Posts: 1607
Joined: Mon Apr 30, 2012 2:49 am
Location: there is no place like ~

Re: Script not working in caja

Postby jibe on Fri Jun 13, 2014 4:46 pm

Thanks for your reply, eanfrid. :)

eanfrid wrote:4/ use is explained in caja help about scripts

Sorry, but when I click F1 (or the menu) in caja, it just opens this web page. I don't see anything about caja in the Mate PDF...

Where is this help you are talking about ?

eanfrid wrote:5/ my method for system-wide scripts is to store them into a folder under /usr/local/bin/caja_scripts and make a symlink to them in ~/.config/caja/scripts

Ok. So, you are obliged to have a link for each user... I thought that there was a way as for Nautilus : you can put also Nautilus scripts in /usr/share/nautilus-script...

I changed my script according to the example you give :
Code: Select all
#!/bin/sh
FILE=$(echo "$CAJA_SCRIPT_SELECTED_FILE_PATHS")
gpg -d $FILE >${FILE%.*}

but it is always the same : not asking for the passphrase, and gives an empty file...
User avatar
jibe
Level 3
Level 3
 
Posts: 102
Joined: Thu Dec 28, 2006 4:31 pm

Re: Script not working in caja

Postby Pilosopong Tasyo on Fri Jun 13, 2014 11:25 pm

I don't use Mate/Caja, but these caught my attention:

jibe wrote:It's working well in a terminal or a console, but when I use it as a caja script, it gives me an empty file !

jibe wrote:gpg is asking me the passphrase the first time I use it, and never after until I close my session and open a new one.

Based on what's being described in this thread, two things came to mind:

  1. gpg is a CLI-based tool, hence it doesn't have a GUI.
  2. It requires a certain level of interaction (in this case, entering the passphrase when you get prompted to do so).
It runs fine when you execute it from the CLI, but not once you run it directly from the desktop. Reason: It doesn't know how to prompt you for the passphrase because there's no mechanism to present the prompt in the first place. Remember, it asks for the passphrase inside a terminal window; it does not create a pretty GUI box asking for the passphrase. So, in order to make it work properly when you run it directly from the GUI, your script needs to open a terminal window so it can interact with you.

This thread discusses in detail how to make your CLI-interaction-only script work when you run it from the GUI. The TL;DR summary can be found at the end of the thread.

HTH.
Image
o Give a man a fish and he will eat for a day. Teach him how to fish and he will eat for a lifetime!
o If an issue has been fixed, please edit your first post and add the word [SOLVED].
User avatar
Pilosopong Tasyo
Level 6
Level 6
 
Posts: 1103
Joined: Mon Jun 22, 2009 3:26 am
Location: Philippines

Re: Script not working in caja

Postby jibe on Sat Jun 14, 2014 5:40 am

Hi,

It's a little surprising :
1 - When it asks for the passphrase, it opens a GUI box. I thought that it will open it anyway, even if not executed in a terminal,
2 - It is not working also when it doesn't needs to ask for the passphrase.

However, I tried your suggestion, and it works !

I had 2 things to change in my script, and one more for the comfort :
1 - change #!/bin/sh into #!/bin/bash
2 - Add the 4 lines given by xenopeek in the last post you pointed.
3 - I don't need a pause after the script execution, so I removed it in xenopeek's code

So, my final script is :
Code: Select all
#!/bin/bash

## Décodage d'un fichier chiffré

# if this script was not launched from a terminal, restart it from a terminal
if [[ ! -t 0 && -x /usr/bin/x-terminal-emulator ]]; then
#   /usr/bin/x-terminal-emulator -e "bash -c \"$0 $*; read -s -p 'Press enter to continue...'\""
   /usr/bin/x-terminal-emulator -e "bash -c \"$0 $*\""
   exit
fi

FILE=$(echo "$CAJA_SCRIPT_SELECTED_FILE_PATHS")
gpg -d $FILE >${FILE%.*}
#rm -f $nomgpg


Thanks, Pilosopong Tasyo :)

I tag this thread as solved, however, I'm curious to have some complementary explanations :

1 - Where is this help that eanfrid talks about and that I did not find ?
2 - Why am I obliged to launch this script in a terminal when the interaction is not needed, and when interaction is done in a GUI box ?
3 - Out of topic here, but why gpg is not asking the passphrase each time ? Not good for the security !
User avatar
jibe
Level 3
Level 3
 
Posts: 102
Joined: Thu Dec 28, 2006 4:31 pm

Re: [SOLVED] Script not working in caja

Postby eanfrid on Sat Jun 14, 2014 5:56 am

I am using MATE 1.8:
536611948719de.png


Edit1: maybe your installation of MATE is not complete (for instance, "yelp" must be installed)
Edit2: I use "gpa" for encryption/decryption and key management with a GUI
Main desktop: Debian GNU/Linux Wheezy 64bit w/custom 3.14 longterm kernel - MATE 1.8.1
(i5 2400@3.7GHz - 16GB DDR3 - HD6770 w/radeon driver - SSD+RAID1)
User avatar
eanfrid
Level 7
Level 7
 
Posts: 1607
Joined: Mon Apr 30, 2012 2:49 am
Location: there is no place like ~

Re: [SOLVED] Script not working in caja

Postby Pilosopong Tasyo on Sat Jun 14, 2014 6:38 am

jibe wrote:It's a little surprising ... When it asks for the passphrase, it opens a GUI box.

TBH, I didn't know it's going to open a graphical dialog box. I based my educated guesses on what I read so far (or maybe I missed something LOL). From past experiences, CLI tools and commands normally don't present dialog boxes when they need you to input something. An example is sudo vs. gksudo. gksudo displays a graphical dialog box while sudo simply prompts you in an open terminal window.

As for your other questions, I'm afraid I cannot answer them. I never used gpg before, so I can't provide accurate answers.

But anyway, glad it solved the problem. You're welcome! :D
Image
o Give a man a fish and he will eat for a day. Teach him how to fish and he will eat for a lifetime!
o If an issue has been fixed, please edit your first post and add the word [SOLVED].
User avatar
Pilosopong Tasyo
Level 6
Level 6
 
Posts: 1103
Joined: Mon Jun 22, 2009 3:26 am
Location: Philippines

Re: [SOLVED] Script not working in caja

Postby jibe on Mon Jun 16, 2014 1:57 pm

Hi,

eanfrid wrote:I am using MATE 1.8:
Edit1: maybe your installation of MATE is not complete (for instance, "yelp" must be installed)

If I consider what I see in Synaptics, it seems that I have all for Mate, including yelp. But I'm using Maya, and the Mate version is 1.2. Probably it's the explanation...

eanfrid wrote:Edit2: I use "gpa" for encryption/decryption and key management with a GUI

Ok, thanks : I'll have a look. But I like also to have scripts : this one was just to try, in fact I want to launch directly the right application as if the file was not encrypted. Example : decrypt the file, open it in pluma, and re-encrypt.

Pilosopong Tasyo wrote:TBH, I didn't know it's going to open a graphical dialog box. I based my educated guesses on what I read so far (or maybe I missed something LOL). From past experiences, CLI tools and commands normally don't present dialog boxes when they need you to input something. An example is sudo vs. gksudo. gksudo displays a graphical dialog box while sudo simply prompts you in an open terminal window.

Yes. gpg is a little different, as it does open a graphic box (like gksudo), but also allows you to type the passphrase in the terminal (lke sudo) ! The two in the same time : If you just cancel the GUI box, you'll be still able to type your passphrase in the terminal. But if you give it in the GUI box, it will stop to wait for your answer in the terminal and decrypt he file.

Pilosopong Tasyo wrote:As for your other questions, I'm afraid I cannot answer them. I never used gpg before, so I can't provide accurate answers.

Ok, no problem : I'll open a new topic for that.

Thanks everybody for your help ! :)

[Edit] : added link to topic about gpg passphrase.
User avatar
jibe
Level 3
Level 3
 
Posts: 102
Joined: Thu Dec 28, 2006 4:31 pm

Re: [SOLVED] Script not working in caja

Postby eanfrid on Mon Jun 16, 2014 3:09 pm

jibe wrote:Hi,

eanfrid wrote:I am using MATE 1.8:
Edit1: maybe your installation of MATE is not complete (for instance, "yelp" must be installed)

If I consider what I see in Synaptics, it seems that I have all for Mate, including yelp. But I'm using Maya, and the Mate version is 1.2. Probably it's the explanation...

To make sure: of course you must also have installed mate-user-guide, did you ?
Main desktop: Debian GNU/Linux Wheezy 64bit w/custom 3.14 longterm kernel - MATE 1.8.1
(i5 2400@3.7GHz - 16GB DDR3 - HD6770 w/radeon driver - SSD+RAID1)
User avatar
eanfrid
Level 7
Level 7
 
Posts: 1607
Joined: Mon Apr 30, 2012 2:49 am
Location: there is no place like ~

Re: [SOLVED] Script not working in caja

Postby jibe on Mon Jun 16, 2014 5:34 pm

mate-user-guide ? No... I have not that in my synaptic ! I thought that help should be in the standard repos and that if there is no, it's because no help has been done...
User avatar
jibe
Level 3
Level 3
 
Posts: 102
Joined: Thu Dec 28, 2006 4:31 pm

Linux Mint is funded by ads and donations.
 

Return to Scripts & Bash

Who is online

Users browsing this forum: No registered users and 1 guest