How to use shortcut to switch two color palatte?

I get two color palatte to use one is light and the other is dark.

I want to use a command binding to shortcut to switch between the two. how to make it? Any hint will be ok. Thank you

Have a look at the section on “Using global Keyboard Shortcuts” at https://tiddlywiki.com/

The active palette is saved in the tiddler $:/palette

1 Like

Try this:

STEP 1: Create a tiddler named $:/config/shortcuts/switch-palette, containing text:

ctrl-shift-X

This is the “key binding” for your shortcut.

STEP 2: Create a tiddler named $:/config/ShortcutInfo/switch-palette, containing text:

Switch between palettes

This is the description for your shortcut. The “switch-palette” key binding will now be listed in the $:/ControlPanel “Keyboard Shortcuts” tab, which you use to quickly change the assigned key.

STEP 3a: Create a tiddler named $:/config/ShortcutActions/switch-palette, tagged with $:/tags/KeyboardShortcut, containing text:

<$set name="palettes" filter="[all[tiddlers+shadows]prefix[$:/palettes]]">
<$action-setfield $tiddler="$:/palette"
   text={{{ [enlist<palettes>after{$:/palette}] ~[enlist<palettes>first[]] }}}/>

STEP 3b: Also in $:/config/ShortcutActions/switch-palette, add a field named ‘key’, with a value of:

((switch-palette))

This associates the indicated $action-setfield with the key binding defined in $:/config/shortcuts/switch-palette.

With these three tiddlers defined, you can now press “ctrl-shift-X” to cycle through all the defined palettes.

Note: to switch between just two specific palettes (e.g., “ContrastDark” and “ContrastLight”), change the first line of $:/config/ShortcutActions/switch-palette to:

<$set name="palettes" filter="[[$:/palettes/ContrastDark]] [[$:/palettes/ContrastLight]]">

enjoy,
-e

2 Likes

Thank you ~ But you seems miss the $:/tags/KeyboardShortcut tag. Thanks a lot

Hi about this line of code [enlist<palettes>after{$:/palette}] ~[enlist<palettes>first[]]

What is the meaning of the ~ mark? I cant find the answer in the filter operator.

https://tiddlywiki.com/static/Filter%20Operators.html

That is a filter run prefix, see https://tiddlywiki.com/#Filter%20Expression

In contemporary wikitext :else is equivalent to ~.

1 Like