3

I want a simple semi-safe command that encrypts a file using gpg symmetric encryption and then remove the original file. In the terminal this command works fine:

 gpg --passphrase-file /home/xxx/.gnupg/sympass --symmetric <file> && rm <file>

where <file> is the file to be encrypted (and deleted). This works fine in the terminal, but when I try to do a custom action in Thunar in this way

xfce4-terminal -e gpg --passphrase-file /home/xxx/.gnupg/sympass --symmetric %f && rm %f

and try to use this action in Thunar, nothing happens. Why, and is there some way to debug thunar custom actions?

muru
  • 193,181
  • 53
  • 473
  • 722
Bengt Olsson
  • 638
  • 1
  • 5
  • 17
  • Does just `xfce4-terminal -e gpg --passphrase-file /home/xxx/.gnupg/sympass --symmetric %f` work? – muru Apr 03 '16 at 10:12
  • Nope, didn't work... :( – Bengt Olsson Apr 03 '16 at 10:33
  • 1
    What about `xfce4-terminal -x gpg --passphrase-file /home/xxx/.gnupg/sympass --symmetric %f`? – muru Apr 03 '16 at 10:34
  • I think you can just script the `xfce4-terminal` command and call `gpg --passphrase-file /home/xxx/.gnupg/sympass --symmetric %f && rm %f` directly. – Thomas Apr 03 '16 at 10:39
  • @muru that worked! But not with && rm %f, then it seems to delete the file before encrypting... – Bengt Olsson Apr 03 '16 at 10:43
  • @BengtOlsson try escaping the `&&`: `xfce4-terminal -x gpg --passphrase-file /home/xxx/.gnupg/sympass --symmetric %f '&&' rm %f` – muru Apr 03 '16 at 10:44
  • @muru no didn't work, back to nothing happens – Bengt Olsson Apr 03 '16 at 10:56
  • Put the whole thing in a script (say `xfce4-terminal -x gpg --passphrase-file /home/xxx/.gnupg/sympass --symmetric "$1 && rm "$1"` in `~/bin/foo.sh`), and use `/home/user/bin/foo.sh %f` as the action. What happens? – muru Apr 03 '16 at 10:59
  • Created foo.sh and made it executable `#!/bin/bash xfce4-terminal -x gpg --passphrase-file /home/xxx/.gnupg/sympass --symmetric "$1 && rm $1"` didn't work, nothing happens – Bengt Olsson Apr 03 '16 at 11:17
  • With `#!/bin/bash xfce4-terminal -x gpg --passphrase-file /home/xxx/.gnupg/sympass --symmetric "$1" && rm "$1"`same behavior as before, deleted file only – Bengt Olsson Apr 03 '16 at 11:24
  • What if you set the action to `bash -c "gpg --passphrase-file /home/xxx/.gnupg/sympass --symmetric %f && rm %f"`? – terdon Apr 03 '16 at 11:39
  • @terdon No luck... also tried to remove && rm %f , still no luck – Bengt Olsson Apr 03 '16 at 12:51
  • That's strange, I just tried it here (Arch Linux, Thunar 1.6.10) and it worked as expected. Try opening a terminal and running `thunar` from there. Then, try the custom action. If it fails, you should see an error message in the terminal you launched it from. What does it say? – terdon Apr 03 '16 at 12:56
  • @terdon There was an instance of Thunar running as a service I think. After killing it and restarting thunar from the command line your suggestion worked as wanted. Thanks! – Bengt Olsson Apr 03 '16 at 13:07
  • Wait, now I killed that instance and started Thunar from the menu, and now it doesn't work. Is there some user right issue? (only my user can read the passphrase file). Damn that you can't get any console log when starting Thunar from the menu. – Bengt Olsson Apr 03 '16 at 13:12

1 Answers1

6

There are two issues here. One is that the && is not recognized and you need a full shell and the other is that in order for it to run, you need a tty which thunar doesn't have when launched from the GUI menu. So, first write a script with these contents:

#!/bin/bash
gpg --passphrase-file /home/beos/.gnupg/sympass --symmetric "$1"  && rm "$1"

Make the script executable (chmod a+x /path/to/script.sh) and then set the action to:

xfce4-terminal -x /path/to/script.sh %f

That should cause it to run in a terminal and in a normal bash session so it should work as expected.

terdon
  • 98,183
  • 15
  • 197
  • 293
  • @BengtOlsson that's odd. Has the action changed? Perhaps it wasn't saved before? Could you come into [chat](http://chat.stackexchange.com/rooms/201/ask-ubuntu-general-room) and ping me (`@terdon`) so we can debug it? – terdon Apr 03 '16 at 13:35