Automatic toggle of "Filter Labels" on Dark/Light mode switches

This script is a workaround until this feature request is implemented. It listens for a theme change event and toggles the appropriate dark/light 'Labels/Label Assignment' filter labels, which you should prepare beforehand: for example, if you have:

  • a filter label "Archives" that uses
  • a color label "Archives Color"

then you should create an extra pair:

  • a color label Archives Color Dark (or use a . instead to make the visible text shorter in your lister) with whatever dark mode colors you want to use the
  • a filter label Archives Dark that would be mapped to use Archives Color Dark

Then configure this script with 2 variables:

  • filters: Light mode filters (a list), e.g., "Archives"
  • posDark: Dark mode filter suffix, e.g., " Dark" to toggle "Archives Dark" (mind ␠ in the beginning if you use one!)

Script:
cb.FilterToggleOnThemeΔ.opusscriptinstall (2.8 KB)

If you read the Script Object part of the manual more carefully, you will notice that:

  • Script.Vars represents variables that are assigned to this particular script, but can only be accessed by the script itself (their use is transparent to the script's user).
  • Script.config holds all the configuration values for the script. (The ones you stablish in OnInit() function) The user can then edit these values in Script Preferences.

e.g. to access within your script to "posDark" value:
var posDark = sC.posDark; // returns whatever user set in Script Preferences dialog for that entry

Sidenote : Another more simpler way to define user variables in OnInit() function without using another function can be:

initData.config_desc = DOpus.Create.Map();
initData.config.DebugOutput= false; 
initData.config_desc('DebugOutput') = 'Enable debug output in the "Script log"';
initData.config.filters= DOpus.Create.Vector("Archives"); 
initData.config_desc('filters') = 'EDIT SCRIPT MANUALLY!!! Light mode filters (a list), e.g., "Archives"';
initData.config.posDark= " Dark"; 
initData.config_desc('posDark') = 'EDIT SCRIPT MANUALLY!!! Dark mode filter suffix, e.g., " Dark" to toggle "Archives Dark"\n(mind ␠ in the beginning if you use one!)';
1 Like

Thanks for the explanation, I've already found that bug and fixed it while checking my old script! (pity you haven't noticed the post edits in time)

You're right, reading carefully helps, but I just refreshed on the vars part initially, and nothing threw me off there, config data is also "scoped to the script" :slight_smile: