Question: Button for "Automated Folder Size"

+1 for a command that turns foldersize-calculation on/off.

A new Set CALCFOLDERSIZES command has been added for Opus 11 beta 5 (note: not out yet; we just released beta 4) which can be used to toggle the Preferences option.

Cool!

Really? After I juuuuust wrote this?

' OnAfterFolderChange_getsizes:
' Revision:    1.0.3
' (c) 2014 steje
'
' This is a script for Directory Opus.
' See http://www.gpsoft.com.au/redirect.asp?page=scripts for development information.

' This script is intended to provide a way of simulating the ability to 'toggle' the
' 'Calculate folder sizes automatically' option in Prefs. It works by checking if a
' lister scoped variable named 'autosize' is set, which should be set and unset as
' needed using a normal Opus hotkey or button using the @set directive...
'
' This version of the script currently operates on any type of folder, and doesn't
' currently offer the granularity of control of the actual Prefs option...
'
' Note also that this version of the script also operates on a per lister basis...

Dim DEBUG
DEBUG = false


' Called by Directory Opus to initialize the script
Function OnInit(ByRef initData)

   ' Provide basic information about the Script
   initData.name = "OnAfterFolderChange_getsizes"
   initData.desc = "Check for lister variable on folder changes to auto-calculate folder sizes or not"
   initData.copyright = "(c) 2014 steje"
   initData.default_enable = true

End Function


' Called whenever the folder is changed
Function OnAfterFolderChange(ByRef afterFolderChangeData)

   ' Check if the folder read was successful
   if afterFolderChangeData.result Then
      Set objCmd = DOpus.CreateCommand
      objCmd.SetSourceTab(afterFolderChangeData.tab)
      if objCmd.IsSet("$lst:autosize") Then
         logMsg("The 'autosize' lister variable is set!")
         ' Clear the list of files that objCmd.RunCommand will operate on in case the 'Automatically select first file in folder' Prefs option is set
         objCmd.ClearFiles
         objCmd.RunCommand("GetSizes")
      else
         logMsg("The 'autosize' lister variable is NOT set!")
      end if
      Set objCmd = Nothing
   end if

End Function


' Subroutine to allow toggling of the global DEBUG variable to control whether logging is performed or not
Sub logMsg(ByRef message)

   if (DEBUG) Then
      DOpus.OutputString(message)
   end if

End Sub

LOL...

Doh! Neat script, though.

Thanks, maybe woulda been neater if you hadn't made it obsolete before I even got a chance to post it :slight_smile:... lol

Maybe I'll post it to the Scripting forum anyway as another example of an Event driven script. I can see stuff "like" this being useful in general... particularly if you guys entertain the request to toggle button on/off/highlight state based on @set vars -> DO11: [FR] Test @set variables with @toggle?

Yours is still useful because it's Lister-local rather than a global setting.

Plus it's a nice example :slight_smile:

Ah, well that makes me feel better :slight_smile:. To your point, this is one of the aspects to your scripting enhancements that I find REALLY promising. The prospect of having the ability to make subtle behavioral modifications or extensions to things that may already be possible in Opus to some degree ourselves or for other users, without having to continue barraging you guys with endless feature requests.

So stoked with what you've done to make these things possible!

Ditto. And I hope to see many more interesting ideas posted to the Scripting forum. I have been doing a bit of experimenting too and except to have something in a fit state (i.e. properly documented) to add soon. I'm sure we can all learn a lot from each other.

Regards, AB

I've got a few sample script ready to share - but would like to package into an OSP. Just wondering about how to specify the icon for a .OSP archive.

thx @ leo + steje

Dumb question: how can I use the new switch ?

Set CALCFOLDERSIZES=toggle seems to do nothing here (actually no parameter seems to change anything)

thanks,
t.

How strange - confirmed. Seems to be busted now in a quick test, but I could have sworn it worked when I tried it immediately after Beta 5 released.

At any rate, my version works :slight_smile:

Toggle by itself doesn't work, because if the option is turned off Opus doesn't know what setting you want to toggle it on to. You need so specify toggle in conjunction with one of the other keywords (e.g. Set CALCFOLDERSIZES=local,toggle).

I tried some variations, including the one from the helpfile (Set CALCFOLDERSIZES=local,toggle,skipjunctions) without luck.
Even CALCFOLDERSIZES=local does not work here.

How are you determining that it doesn't work? (i.e. what are you expecting to see?)

Neither the calculation starts nor the prefs setting change.

It's working fine here. (I tried Set CALCFOLDERSIZES=local,toggle.)

Note that you will not see folder sizes calculated until you refresh or change folders (since that is when automatic calculation happens, if it is on).

Also note that you won't see the Preferences option change if the Preferences dialog is open when you change it. (Cancel the dialog and re-open Prefs, and you should see it has changed. OTOH, if you click OK then you will overwrite the setting with what's shown in the Preferences dialog.) This is the same for most commands which toggle Preferences settings. The Preferences dialog takes a snapshot of the configuration, which you can then edit in the dialog, and finally either cancel (throwing away the snapshot) or apply (saving the snapshot over what the main program actually uses).

ok, that probably bluffed me. It is working now, thanks.
Is there a way to refresh the folder by script ?

Go REFRESH=source or similar.

But you could just run GetSizes if that's your aim.