I'm wanting to write a script to add a * or something to tab labels when they are inactive and their contents change (i.e. a file in the tab is changed/deleted/created etc).
However, I can't quite come up with a good way of doing this.
I've tried an (unsupported) timer as such:
Function OnStartup(startupData)
Dim lister
While true
DOpus.Output DOpus.Listers.Count
For Each lister in DOpus.Listers
DOpus.Output " " & lister.Tabs.count
Next
DOpus.Delay 1000
Wend
End Function
However, it seems that the 'DOpus' accessed in the OnStartup is not the 'real' one? The count is always 1 & 1, regardless of how many listers/tabs you open after startup!
I've also considered running an external process when a tab is deactivated, and using the normal Windows file system change detection, which is super easy in something like C# - any changes could use dopusrt to change the tab name or run a custom command in Opus. I was also thinking a script in Directory Opus could wait for changes using WMI & winmgmts (example).
Before I go too far with hacking around with this, does anyone have any thoughts, suggestions or experience with similar things?
I'm not sure it's a good idea to have scripts that run in the background forever and never return from the OnStartup event. They could delay things like startup or shutdown, for example.
That said, the problem you are seeing is because the DOpus.Listers collection you are given is a snapshot. It won't change underneath you. If it did, it would make it impossible to loop through all the listers as the thing you were looping through could change while you were looping through it (which could cause all sorts of errors in your code if it happened).
As per the docs, "To re-synchronize the collection, call the DOpus.listers.Update method."
Of course! I'm totally on the same page - I don't want to use this method at all (hence I said it was unsupported), but I can't think of another way to do it at the moment.
Thanks! I'm not sure I want to continue down this route with the infinite loop thing, to be honest - hence this thread being about brainstorming other ways of doing it
You could use an external tool for monitoring folders (a few exist) and have it tell Opus to run a script command when it notices a change. That command could then update the labels (and you could tell it which thing changed when running it, so it does't have to re-calculate that detail when the thing triggering it already knows).
That leaves the question of how to make the monitoring tool know which folders you are interested in. You can use dopusrt.exe to get a list of currently open folder tabs and their paths.
As to which monitoring tool to use, I don't know. There are a few of them out there. You could also write your own, e.g. have the loop you were thinking of placing in OnStartup in an external script that runs independently of Opus. (It could be started in OnStartup and told to shut down in OnShutdown.)
Leo, Sounds reasonable, and along the same lines of my thinking.
Also, the external tool can listen on a named pipe, which you can write to from a vbscript inside Opus to keep the tool updated as to which folders to keep an eye on.