The Haiku/BeOS Tip Server
Tips and tricks for Haiku/BeOS users

Empty the Trash from scripts

Contributed by: Nate LaCourse
This tip is valid for: Both BeOS and Haiku

So you want to hack up a quick script that will, for example, clear your NetPositive cache and history, delete all those temporary buffers that vi leaves around, and best of all, empty the Trash.

On first thought, you might think this would be a simple task, just:

rm -rf /boot/home/Desktop/Trash/*

Right? Right? Wrong!

There are two reasons why that won’t cut the mustard. First, if you have trash originating from more than one volume, only the trash coming from your boot volume will actually be deleted. Secondly, you won’t get any visual indication of the emptying process, like you would if you were to empty your Trash via Tracker.

So, you might get fancy and whip this out from your little bag of tricks:

 ugly=`find /*/home/Desktop/Trash -path /boot/home/Desktop/Trash - prune -o -maxdepth 0 -printf '%p/* %p/.[^.]* '`

rm -rf $ugly 

Well, that will get rid of one of your problems, but you’re still not going to have any visual indication of the emptying process.

Hey! Why not tell Tracker to just empty the Trash for you:

hey Tracker 'PDEL' of Trash

That’ll do ya. So the answer is deceptively simple. All you have to do is tell Tracker to empty the Trash, just as you’d do it directly from the Tracker itself. Gotta love those BMessages.

Posted in Scripting

(comments are closed).