Command: ListerClock (show a simple clock in lister title)

This script is fully commented and shall be of some help to anyone trying to get going with DO scripting.

ListerClock - a simple script command to display the current time and DOs version information in the lister title

Description:
It is an easy example on how to create a script command, use global variables and how to set a custom title every second.
The script also explains some of the modifications done to a script, if it has been prepared for uploading with the
ScriptWizard add-in.

Usage:
Create a button, which calls "ListerClock" and push it once or press ">" and enter "ListerClock" to start the clock.
Push the button again or rerun the command to disable the clock and re-enable the default lister title again.

Installation:
To install the command, download the *.js.txt file below and drag it to Preferences / Toolbars / Scripts.

Download:


GPSoftware note: We recommend against using scripts that have commands or event handlers which never return. While they may work OK today, they could cause problems in the future, such as update installs not progressing because the program is waiting for a command to finish which never does.

Brilliant, tbone!!! I now have the clock and the version number. I have adapted the Set ListerTitle command so that I also have another couple of global variable that I wanted, and I have checked that they do indeed update within a second if I change them.

Thank you very much indeed, and I hope very much that others will find the script useful.

You've put a great deal of thought into the comments as well as into the code itself, and I will go through them line by line as best I can to understand the logic. My problems with scripts come at the very beginning — declaring variables, preparing functions, syntax, and so forth. I'm not sure that it's possible to pick this stuff up, at least I'm not understanding it properly, and it looks rather as if one has to read a systematic textbook on scripting before tackling the DOpus scripts.

Unfortunately, there seems to be a bug. When I select a file or multiple files, they get deselected again within 1 second, in time with the seconds being updated. I have no idea why this is happening. When I press the "ListerClock" button again so that the time is no longer updated, the problem disappears.

Updated to v0.2

  • do not deselect selected items, by adding "data.func.command.deselect = false;" somewhere at the top of the main function.

Yes, I guess some basic programming/scripting skills are required to prevent getting too frustrated at the beginning with DO scripting.
But there's a lot of documentation out there, maybe you like to read something like this: tergestesoft.com/~manuals/jslang/JStutor.htm

In case you use google to search for JScript scripting techniques and tutorials, notice that you will be given a lot of "Javascript" related hits.
Javascript and JScript are not covering the same functionality to 100%, but I guess 95% of pure Javascript code will also be valid JScript, just keep that in mind.
For getting pure JScript hits from google, I always add "-javascript" to the search query, which should be necessary for advanced topics only.

Thanks, tbone. I downloaded and installed v0.2 and checked that the bug had gone. I then modified the Set ListerTitle line, and the bug was back!!! (That is, selected files become unselected within 1 second).

I fiddled about adding and subtracting bits of my line until I had established that the presence of the %L layout token, anywhere in the line, triggered the bug, and nothing else in my line did. Here's my buggy line:

'Set LISTERTITLE="Directory Opus V'+DOpus.version.product+'.'+DOpus.version.build+ ' {$Glob:ConfigFileName}          {Date|YYYY MMMM dd} @ '+timeNow+'          Source:  %P          Destination:  %D         Layout:  %L"'

I tried a script alternative — replacing %L by +DOpus.listers.layout+ does not trigger the bug, but it unfortunately yields "undefined" as the name of the layout. I assume that I have the wrong code.

Unrelated: Is it possible to modify the code so that your titlebar runs when DOpus starts? (This is hardly a problem because it's very easy to add the "ListerClock" command to the startup routine.)

Thanks very much for the JScript reference. It looks very sensibly written. I'll start reading.

The most efficient way to avoid deselection of files used in functions is disabling the option Preferences=>File Operations=>Options=>Deselect Files used in functions.

Very interesting, kundal. With that box unchecked, the token %L seems to work perfectly when just one item is selected. When more than one item is selected, however, the titlebar becomes unstable, either reverting to the previous titlebar or flicking between the two.

By the way, after reading some of tbone's online JScript reference, the DOpus remarks about "objects" made more sense — DOpus.listers.lastactive.layout puts the correct layout at the top of the active lister when ListerClock is run, and there are no problem with selecting items. The problem remains that, presumably because it is not a token like %L, the next lister that I open comes up showing the same layout as the first, and the ListerClock command has to be run twice from its toolbar to make it show the correct layout.

Thank you for that that - I am forcing myself to learn some DO scripting and your scripts are very great source of help.

In the meantime just wanted to inform that above script (v0.2) makes ALT key (to access the Menu Toolbar) hard to use. Every time the title bar gets updated the Menu Toolbar loses its focus (explanation: when I press ALT, focus goes to Menu Toolbar and at this moment if I'm not quick enough to press Arrow Down to open menu the focus is lost after clock changes).

There could be a few strange issues like that. I'm not sure it's a great idea to have a script command which never completes and endlessly runs additional commands once a second, to be honest. :slight_smile: There's a clock on the Windows Taskbar already.

Thanks, Leo . . . and that, of course, was your original advice. But we've learnt a few things. By the way, what peCeha reports doesn't seem to be happening on my system.

I was intending to place other variables on the TItle Bar, so I may attempt to use tbone's reference and the DOpus Help to cut his code back to a one-off non-looping script that I can trigger with a button. Wish me luck. (Or I may stay with 0.2 and forget about the layout.)