Layout UpdateOnClose: Autosave non-default layouts when listers close

Note: This script requires a minimum Opus version 12.2...

This script was written in response to a request described in the following discussion:

Save positions of closed windows?

What does it do?:
This script handles the OnCloseLister event so that when a lister is closed the script will look to see if it was part of a user defined lister layout. By default, the 'default lister' is excluded from this behavior - since Opus has long had it's own option for automatically updating the default lister. However, handling of the 'default' lister can be enabled in the scripts configuration options in Prefs.

How to install and use it?:
The script is provided here as an Opus Script Package... which in turn is actually a zip file with a VBScript packaged inside. It can be installed by either manually copying the OSP file to the /scripts folder, or via drag-and-drop into the Preferences / Toolbars / Scripts page.

Download: Layout_UpdateOnClose_Handler.osp (3.27 KB)
Notes:
2016-11-22: v1.0.2 - Initial release...


After installing the script package, you can set the ExcludeLayoutList option to EXCLUDE any saved lister layouts you do NOT want to update when it's listers are closed. You can also enable the automatic update of the 'default lister' layout by setting the IncludeDefaultLayout to True. If this is enabled, there are also additional SetAsDefaultForce and SetAsDefaultQuiet options to pass through the related options to the Prefs SETDEFAULTLISTER command. This can all be done via the scripts Configuration dialog.

NOTE: about multi-lister layouts... With this initial release, only single lister layouts are supported. There is no way to interrogate Opus for details about a lister layout in order to automatically determine whether or not the script should save all listers or just the one being closed. I'm more than happy to listen to ideas on how this could be improved (prompts, use of additional variables, etc).


In addition to the qualifier keys that can be set to enable/disable the scripts execution (qualifier keys require the Always_On option to be set to True), script execution can also be enabled by the use of an Opus environment variable called (requires the Always_On option to be set to False).

Here is a sample toolbar button that toggles the lister scoped variable (the script supports lister or global scoped variables) which you can copy and paste directly to your toolbar:

<?xml version="1.0"?>
<button backcol="none" display="both" label_pos="right" textcol="none">
	<label>Layout_UpdateOnClose</label>
	<icon1>#savedlayoutsedit</icon1>
	<function type="normal">
		<instruction>@toggle:if $lst:layout_updateonclose</instruction>
		<instruction />
		<instruction>@ifset:$lst:layout_updateonclose</instruction>
		<instruction>@set lst:layout_updateonclose</instruction>
		<instruction />
		<instruction>@ifset:else</instruction>
		<instruction>@set lst:layout_updateonclose=true</instruction>
	</function>
</button>

...Feedback welcome.

2 Likes

Thanks for doing this

But, I cannot get it to work. The script and button are installed/added correctly, but I cannot figure out how to use the button itself or how it should actually work. Toggling it apparently does nothing on my system.

Does it rely on other settings in the DOpus config?

Go into the scripts option in Prefs and post a screenshot of how you've got it configured. Also, enable the DEBUG option (set it to True), and open and close a saved lister layout. After doing so, post the /dopusdata\Logs\Script Output.txt file here and I'll see whats happening.

I was gearing up to learn what I had to do to write such a script....and to my sheer delight I find it written already.
@steje thank you very much sir.
I find it MUCH faster to learn to script if I start with something working and then view/edit.
Thanks once again.

Thanks for this script! Is there a version that also auto-saves periodically to avoid losing data on crashes?

You don’t need a script for that; it’s built-in.

The builtin doesn't update saved layouts, so, for example, if on Windows shutdown something goes wrong or DOpus crashes, you'd lose your tabs/layout

This script provides a more resistant backup solution by "abusing" layouts

Here is my updated version, which

  • adds per-Lister :clock1:timers so that if any of the lister layout changing events (if I got them correct, see this post) happens after, say, 5 minutes since the last time layout save attempt (for the same lister), layout is saved (all the regular exclusion rules apply)
  • allows including/excluding multiple modifiers
  • allows excluding named layouts based on a prefix (e.g., layouts starting with '✗' are ignored)

backup.LayoutOn⎋.opusscriptinstall (6.1 KB)

1 Like