Manage Global Variables

Overview

I regularly refer to global variables in commands and scripts and to make life easier I knocked up a simple dialog driven front end.

Installing the script below adds a $SetGlob command to Opus. (The $ has no special meaning; it's just part of the command's name.)

Usage

Executing $SetGlob with no arguments simply lists all current global variables and their settings.


The following example shows how to use $SetGlob to selectively create new, replace existing, or list global variables.

$SetGlob Test "Source C:\Relay\Source" "Target C:\Relay\Target" Temp Test2
  • In this example, Test and Temp are existing variables, the rest are new.

  • Enclose "Var Value" in quotes to define a value to be assigned to var. Source and Target show how this is done.

  • New unquoted variables, such as Test2, have no associated value string and are defaulted to TRUE.

Running the command above would result in a dialog like this:


If you then run $SetGlob on its own again, the dialog will appear again to show the updated status.

If you uncheck some variables and push OK again, those variables will be deleted:

Running $SetGlob on its own again will show you the new state:


Installing:

  • v2.1: Set Global.vbs.txt (5.7 KB)
  • Download and then drag to Preferences / Toolbars / Scripts.

Changes:

V2.x Handles all global variables, not just (TRUE/FALSE) switches.

Regards, AB

Interesting idea. Does this assume that all of the vars are boolean?

The short answer is yes. For now, I am only testing whether a variable is SET or NOT SET. The dialogs give me a quick way of checking or setting the status of existing switches and adding new switches. Nothing fancy in v1.0. :slight_smile:

Regards, AB

Nice one! But I wondered at first, what has this thing to do with wether to open something in new tabs. o)
"openinnew openinnewtab" in "$SetGlob openinnew openinnewtab bcbeta" refers to variable names I guess?

Yes, these are global variable switches. I use BCBETA to determine whether to execute Beyond Compare 3 (Stable) or Beyond Compare 4 (Beta). The other switches are used by a custom $GO command to set the default behaviour. e.g. If OPENINNEW is set, then [i]$GO C:[/i] (with no modifier key pressed) will open C:\ in a new window. I have a whole suite of $GO buttons defined and also a set of hotkeys mapped to $GO .

Regards, AB

AB, I hope it's OK for me to give a warning here to people who may want to try your script. I downloaded it and fiddled with it, but it seemed to reset all my global variables from their previous values to "True", and I had to restore my uservars.oxc file from a previous backup. I then found that even the command $SetGlob without any further parameters or further action seems to reset all my global variables to "True". Apologies if I am misunderstanding something.

BTW, what is badly needed is a script that will display all the global variables in a convenient manner and allow variables to be reset, deleted or added. The file uservars.oxc is more general than an .xml file because it allows things that the strict and somewhat arbitrary xml naming rules disallow, so an xml viewer may or may not work, depending on the names chosen for the variables. The only way that I can view or edit the list as a whole is by opening uservars.oxc as a text file, which is clumsy to do, inconvenient to interpret visually, and error-prone when editing.

Julianon - quite OK. I'm testing an updated version that handles all types of global variable, not just switches. It will also be able to list all current global variables and values. I expect to post in the next couple of days.

Regards, AB

(Version 2 was posted here, but has been moved into the first post.)

AB, that's looking very nice! Thank you! I only wish that I could write script. (And there is no longer any disturbance to my existing variables.)

I put your file "Set Global.vbs" into the directory "Script addins". Then I fiddled about trying to write a button that would add parameters to the command, and would also allow no parameters. All I can come up with so far is the odd-looking solution:

@Set TheParameters={DlgString|Enter the parameters.}
$SetGlob {$TheParameters} ""

which seems to cover all bases, including no parameters, and spaces in filenames. You may well have a better solution.

Some cosmetic details:

  • It would be good if the message box were a full Windows window. Vertically, I would like to see a screenful of variables at one time. Horizontally, some of my variables are too long for the box (and hovering doesn't fill out the dots).

  • A really nice addition (too much effort for too little gain?) would be to display the variables in two columns that could be separately sorted.

I'm working with the relatively simple dialog box that the DOpus scripting interface provides. I imagine that the broader Windows/VBScript/JScript universe provides more complex possibilities but I will leave those for more adventurous souls to explore, or wait for your feature requests to be added... :smiley:

Regards, AB

Well, the dialogue box you provide is already a lot more convenient to read than the raw quasi-xml-file, so thanks very much AB.

It's interesting that just because one of my variables begins with @, the standard .xml editors, such as Microsoft's 2007 XmlNotepad or MindFusion's XML Viewer, refuse even to read my uservars.oxc file. That's understandable as a default, but you would think that they would have an option permitting such an extension. It clearly doesn't trouble DOpus' internal workings that one variable begins with @.

Nice update AB, I think you are doing as much as you can with what you have to work with. I store a lot of paths in variables, If I remove them the script will ask me to re locate the file when next run. So I'm finding this very handy. Thanks.

When I run command $SetGlob I get an error.

Set Global Variable(s): Error at line 64, position 7
Set Global Variable(s): A method was called unexpectedly (0x8000ffff)

Thanks @wowbagger. Fixed in v2.1 which is posted above

Regards, AB

Yep that worked thanks mate :slight_smile:

Might i suggest that you use the first post as the place to store the latest version and details of the script.

Hello guys! o)

Aussie, what about adding a commandline switch as well as multi-row-button to the leftmost position, to switch between switch tab/lister/global scope? And what about replacing the "Ok" button with a bunch of "Edit", "Copy" and "Delete" buttons, to get more juice out of this beast?
The possibility to edit a vector with an external editor of choice is another idea, what do you think? o)


A customized size of these dialogs really is missing, look how squeezed the content is for me, but that's not in your hands. o)

EDIT:
I agree to wows suggestion, put the most recent version into the top and maybe also dump the old one if it's obsolete.

EDIT2:
And maybe also remove the version string from the uploaded filename and put it into the attachment/file-comment box, like this e.g:
v2.1 / 2015.04.28 - bugfix
This makes it clear when this version was uploaded and prevents duplicates when people drag downloads into /script addins.

@tbone

I'm a bit busy at the moment but will certainly consider adding some bells and whistles when time permits. Anyone else who wants to have a go in the meantime is welcome..... :smiley:

Not sure why your dialog is so compressed. Mine certainly is not. I'm on v11.13.1. This screen grab was taken on a Windows 7 system. I checked in an XP virtual machine and the dialog was also OK (i.e. wide) there.


Regards, AB

Thanks for testing the dialog size on your side. If anybody knows the magic behind that, let us know! o)

In case you start enhancing it: Editing a vector in an external editor maybe wasn't that of a good idea. I think this type of dialog can also be used to list/edit vector items. If implemented recursively, that would even work for nested vectors.