Recycle Bin Button With Status

The following scripts and buttons will give you a multifunction recycle bin button... (see attachments below)

Left-click goes to recycle bin
Right click empties recycle bin and updates button icon to empty recycle bin icon. (Optionally plays empty recycle bin wav file)

TestBin Script:
The TestBin script fires on OnActivateLister. It checks the state of the recycle bin and updates the button icon whenever the lister gets activated.
This script is necessary if you delete from windows explorer or other third party programs or if you empty the recyclebin from other locations other than Dopus

Bins icon set:
This is just a small icon set containing only the icons for the recycle bin

How to install:
Drag and drop the script into the scripts section in preferences.

Import the new icon set into icons in preferences

Copy and paste Recycle Bin.dcf onto a toolbar where you want the recycle bin icon displayed
Optionally edit the right-click button to play a sound file

Use the following code for your delete button:

@set glob:Script.RecycleButton=isFull (29 KB)

See also:

A newer, more simple way of doing something similar has been posted here:

Hi goselito,

I tried your kit, because I don't actively use the recycle bin at all and was curious what it would offer.
I played around with it, had some problems and now some suggestions and thoughts to improve on it. o)

  • The script should not count all items in the bin. I had 4000 items in there and this caused a noticeably delay when opening a lister, so just exit the loop after the first increment or test for the .count/.length property of the items collection, wether to set the variable.
  • I think you should use a sensible name for the var instead of "TestVar", what about "Script.RecycleButton" or something?
  • I think there's no need to use a persistent variable
  • The button code modifiers you use in the script, probably have no effect, that toggle thing at least hasn't. You should make use of DOpus.Vars.Set("Script.RecycleButton","isFull"); instead of using button modifiers to create variables.
  • The Button has no icon for me, in case the recycle bin is empty/has been emptied.
  • The button icon is not automatically updated to reflect changes or new items in the bin.. and you cannot do a thing about it, I know. o)

cya, tbone

@tbone, thanks for the feedback.

Will definately change that... I kept creating a new textfile or folder, then delete it while I was trying to get it to work, so with only one or two items in the bin I had no delays, but I can see how this would cause a delay.

I used the persistant variable before I created the script that runs onnewlister, so yes, I will change that also.

From the documentation I thought I needed it to refresh the button to show the new button icon, but I just tested it without @toggle:update and you are right...not needed.

That's weird as I copied my own button from the toolbar and it works for me.

If a file or folder gets deleted in explorer or a thrid party app the button will not update until you start a new lister. It should update immediately though if you delete from a dopus toolbar button that updates the variable.

Anyway, thanks, I appreciate the feedback. Still struggling with the scripting engine, but I am slowly but surely starting to see more and more possibilities the more I get to use. I will work on your suggestions, however, for the more experienced coders in the community, please feel free to tweak the code and post your revisions here :wink:

I checked, you still have absolute paths in that button. Not every icon is linked to the icon set, that's why the "empty bin" and the image for "emptying the bin" don't show for me. You really need to speak to the quality assurence about this. o)

Okay, I have implemented @tbone's suggestions

The toolbar button should also now show all buttons in whichever state it is.

Download the updated attachment and follow instructions in the first post.

@tbone, I get a script error when I try DOpus.Vars.Set("Script.RecycleButton","isFull")
Can you perhaps take a look at Testbin.vbs to see where I am going wrong? (29.1 KB)

code removed..

I can't get it to work on my pc. If there are items in the recycle bin when I open a lister, my button shows the empty icon :frowning:

Did you change the button code, so it checks for "Script.RecycleButton" instead of "TestVar" ?

Now as I write this, my initial suggestion for the variable name "Script.RecycleButton", is kind of nonsense. o) Maybe you change the variable name again to "Script.RecycleBin", "Script.RecycleBinStatus", "Script.CheckRecycleBin" or somehing else making more sense. A proper name just helps to find out where a variable came from and that your code does not interfere with things other people have created ("TestVar" was a good example on how to not name these things o).

This is the button code:

Go /trash

The only difference is in the testbin script.

You Have:

   If objFolder.Items.Count > 0 Then
      Call DOpus.vars.Set( "Script.RecycleButton", "isFull")
   End If

and I have:

	If objFolder.Items.Count > 0 Then
		dim objCmd : Set objCmd = DOpus.NewCommand
		objCmd.RunCommand("@set glob:RecycleButton=isFull") 
		Set objCmd = Nothing
	End If

But my code shows the correct button icon when a new lister is opened.

Thanks for the tips @tbone. My scripting discipline leave much to be

So it works now or.. ?

lol..yes indeed, but without the

Call DOpus.vars.Set( "Script.RecycleButton", "isFull")

Line. I can't seem to make it work with that. But bottom line... it works :wink:

It should work with that line as well, you just need to make sure to correctly use "Script.RecycleButton" as variable name in your buttons, including the "Script." part, as it is part of the variable name and not something to be omitted when used in a button or elsewhere.

Aaaah, I can see where I went wrong now. I just tried it with

Call DOpus.vars.Set( "RecycleButton", "isFull")

Because all my buttons codes uses RecycleButton only, not Script.RecycleButton.

I'm off to bed now, but I will upload a version tomorrow where all buttons and scripts refer to Script.RecycleButton

Thanks for all your help @tbone

My pleasure, giving help is easy if it's welcome. o)

Must ask a little offtopic question here, what is that "ShowInViewerpane" script I saw in your script-list screenshot? I'm looking for something to control the viewerpane, so wondered what it is. o)

If the recycle bin is full and you empty it at another place (e.g. using the context menu of the desktop icon) the icon will not update. You should add something like this at the end:

	If BinCount > 0 Then
		dim objCmd : Set objCmd = DOpus.NewCommand
		objCmd.RunCommand("@set glob:RecycleButton=isFull") 
		Set objCmd = Nothing
		DOpus.vars.Delete ("RecycleButton") 
	End If
End Function

Instead of Function OnOpenLister(openListerData) I'm using Function OnActivateLister(ActivateListerData). This updates the icon more easily if something was deleted outside DOpus by e.g. toggleing source/dest.

@kundal, thanks for the feedback. I have updated the script to work on Function OnActivateLister(ActivateListerData). This has the added advantage that the icon is imediately updated if you delete via the context menu as well. I have also implemented all of @tbone's suggestions.

I have quickviewplus installed, but whether you have it or not, I find it way quicker to open a variety of files in the viewer rather than its registered program.

To do that, I edit the double-click event for the filetype and let it run the custom command ShowInViewerPane.
It also changes some layout settings that makes it easier for me to select another file to view in the viewer.

I removed some unnecessary lines from your script and made some minor changes:[code]option explicit

' TestBin
' This is a script for Directory Opus.
' See for development information.

' Called by Directory Opus to initialize the script
Function OnInit(initData) = "TestBin"
	initData.desc = "Updates the recycle bin button"
	initData.copyright = "goselito on 01/09/2014"
	initData.version = "1.2"
	initData.default_enable = True
End Function

' Called when a Lister is activated
Function OnActivateLister(ActivateListerData)
	Const RECYCLE_BIN = &Ha&
	Dim objShell
	Set objShell = CreateObject("Shell.Application")
	Dim objFolder
	Set objFolder = objShell.Namespace(RECYCLE_BIN)

	If objFolder.Items.Count > 0 Then
		DOpus.vars.Set "Script.RecycleButton", "isFull"
		DOpus.vars.Delete "Script.RecycleButton"
	End If
End Function

Thanks for showing the ShowInViewerPane-thing, unfortunately it does not what I was looking for, but thanks alot! o)
(Maybe you should clear that post to not unnecessarily mix this thread up? Additionally I suggest removing all script snippets once this reaches a usable state.)

Another thought: Think about people not using the recycle-bin (they might have disabled it completly), how is your script going to handle that, I'd expect it to throw an error, don't know for sure. But Set objFolder = objShell.Namespace(RECYCLE_BIN) could fail then, so there's room for some "on error goto " stuff I guess. You probably also could switch to a "recycle-bin" disabled icon! Huh? o))

Wonder though, why is it actually important for you, to see that there are items in the bin? I normally don't care at all. o)

Thanks @kundal,

I've uploaded a new zip file with the changes.