LinuxQuestions.org

LinuxQuestions.org (/questions/)
-   Linux - Desktop (https://www.linuxquestions.org/questions/linux-desktop-74/)
-   -   How to send file to KDE trashcan via CLI? (https://www.linuxquestions.org/questions/linux-desktop-74/how-to-send-file-to-kde-trashcan-via-cli-484694/)

rshields9093 09-18-2006 12:51 PM

How to send file to KDE trashcan via CLI?
 
Well, that's the simple question. Can I use the command line to send a file to KDE's (3.4) trash can? It seems that KDE is using a particular protocol (trash:/) for this purpose but I can't figure out how to do anything with it via the CLI.

Thanks,

Robert

zetabill 09-18-2006 02:19 PM

It's probably not a fantastic idea to do it but possible. Generally the trash "function" moves the files to a trash folder and then stores information about where it originally was, permissions, etc. So it's a perfect candidate for a protocol. It's probably not too difficult a task to accomplish but it probably won't be as effective as using it in KDE.

Your best bet would be to make your own CLI trash can (mkdir ~/.cli-trash) and then write a bash script that mimicks the rm command but actually uses the mv command to move it to .cli-trash. You could call it trash.. but not rm. Then you could make a script that empties that folder, etc, etc. The real challenge is restoration. Simply moving it to a trash folder means you can't just restore it but actually move it again to where you want it.

With that being said, getting to use the KDE trash can is basically the same thing. You would have to write a trash script that moves it to KDE's trash can and that doesn't necessarily mean that restoration is easy. It might be possible to find the process KDE uses for the trash protocol and either mimick it or possibly use it directly. I can't see how this would be possible without a little KDE hacking... it's a builtin function.

Maybe someone has cracked this and could give their opinions or maybe you could poke around the KDE fora to see if this has been discussed there.

Good luck.

rshields9093 09-19-2006 09:33 AM

Thanks for the reply. I was of course hoping that there was some CLI way to directly access the KDE trash function. But if not, I think maybe your suggestion of making my own cli-trash might be the best route for me. I will poke around a bit more as you suggest, but sounds like I might have a little hobby for this upcoming weekend.

Thanks again for the help.

Robert

hand of fate 09-20-2006 08:07 AM

I've had a look at what sending something to trash from KDE actually does, and it seems fairly simple.

First is moves the file into the directory ~/.local/share/Trash/files.

Then it creates a plain text file caled {file name}.trashinfo in ~/.local/share/Trash/info, containing the text

Code:

[Trash Info]
Path=original path of file
DeletionDate=year-month-dayThour:minute:second

Obviously the bits I've written in blue need to be replaced with the correct information, everything else is written exactly as I've writen it here. Note that the file ends with an empty line.


I can't help you with the coding, but it should be fairly straight forward to create a script that can do that.

rshields9093 10-02-2006 09:08 PM

ah ha. Thanks for the info on how KDE handles trash. That appears to be quite simple and even I ought to be able to code something to handle that. Thanks again for the info. Now I have a little project to work on. :)

grepper 10-06-2006 12:29 AM

You can accomplish this with kfmclient.
Code:

kfmclient --commands
will give you help.
trash is protocol in kde
ie. putting
Code:

trash:/
in konqueror will bring up your trash
(no pun intended)

anyway, here it is:
Code:

kfmclient move your_file trash:/
hth,
grepper


All times are GMT -5. The time now is 09:08 PM.