Quick tip: Always open 'Open' sidebar tab on startup

I found that for personal use, I want my TiddlyWiki to always open with the Open tab selected. Every time I had it on Recent when I saved & closed TW, I found myself manually switching back to Open.

Let’s change that so TW always expands the Open tab the next time you open your wiki!

EDIT: I have replaced my original solution with a smarter solution by Eric Shulman:

Eric's solution
  1. Create a new tiddler, which can be called anything you like and enter \define publishFilter() -[prefix[$:/state/tab/sidebar]] in the body text
  2. Tag the tiddler with $:/tags/Global
  3. Save the tiddler
  4. Save your wiki

If you are curious, see Eric’s post on how and why this works.

Original solution
  1. Go to Advanced Search for System tiddlers, either by:
    • Clicking/tapping :mag: and selecting the System tab, or
    • Navigating directly to $:/core/ui/AdvancedSearch/System
  2. Enter $:/state/tab/sidebar in the search box. You will get an answer like $:/state/tab/sidebar--123456789. This number* could be unique to your wiki.
    Copy the name of the whole tiddler like in the example I gave.
  3. Create a new tiddler, call it whatever you would like.
    I didn’t want to see this tiddler in search results, so I put it behind the $:/ namespace & named my tiddler $:/yan/Always open ‘Open’ sidebar tab on startup
  4. Enter this into your new tiddler and replace the number with your wiki’s unique code <$action-setfield $tiddler="$:/state/tab/sidebar–YOUR_NUMBER_HERE" $value="$:/core/ui/SideBar/Open" />
  5. Tag your tiddler with $:/tags/StartupAction**, save the tiddler, and save changes to your TiddlyWiki.

* See documentation for the State Mechanism if you are interested in what this number means.
** More options are available for startup actions, but the basic type of action met my needs.

If you followed all the steps right, Open will be pre-selected the next time you open your TiddlyWiki, regardless of what tab you last had expanded when you saved your wiki.

Hope this helps any other TW beginners!

4 Likes

Thanks for sharing your solution.

Another angle is simply to prevent certain tiddlers — like state tiddlers — from saving in the first place:

1 Like

Nice!

I have a number of wikis that are meant for consumption by someone else. I aways want these to open in a consistent state, in which all menus are folded. In those, I go a little further than this, and delete all the $:/state/tab/sidebar-* entries. I set the text of $:/config/DefaultSidebarTab appropriately. (For my case, that’s TableOfContents. It sounds as though you would want $:/core/ui/SideBar/Open.)

In a $:/tags/StartupAction tiddler, I have something like this:

<$list filter="[prefix[$:/state/tab/sidebar]]" variable="sidebarTab">
  <$action-deletetiddler $tiddler=<<sidebarTab>>/>
</$list>

<$list filter="[prefix[$:/state/tab/moresidebar]]" variable="moresidebarTab">
  <$action-deletetiddler $tiddler=<<moresidebarTab>>/>
</$list>

Note that $action-deletetiddler can also accept a $filter=... param for deleting multiple tiddlers. Thus, your StartupAction could be written more compactly as:

<$action-deletetiddler $filter="[prefix[$:/state/tab/sidebar]]"/>
<$action-deletetiddler $filter="[prefix[$:/state/tab/moresidebar]]"/>

-e

1 Like

Oh, thank you. I’ve been copying and pasting this code for a few years now. I never really looked back at it until today. That’s a definite improvement!

I think there’s a strong case for introducing a new core setting to accomplish this. We could do it at a high level with a setting that entirely disables the saving of state tiddlers, or a more granular setting that just controls the sidebar tab behaviour.

3 Likes

Thank you for your response Jeremy. I did find a configuration tool under Settings after this post. It was already set to Open, but it wasn’t doing anything.

The tiddler is $:/config/DefaultSidebarTab.

Following up, I tested this an empty.html of 5.3.6. I’m getting the same result for a single-file wiki; the tab is whatever it was when I last saved the wiki, instead of ‘Open’, which is the default setting for $:/config/DefaultSidebarTab.

A $:/state/tab/sidebar-... tiddler is automatically created as soon as you switch to a different sidebar tab. Note that this tiddler title is “qualified”, which means it gets a computed numeric value appended to the end of the title. If you look in the “more > system” tab, you will find something like $:/state/tab/sidebar--595412856 there.

The default value from $:/config/DefaultSidebarTab is only used if $:/state/tab/sidebar-... doesn’t exist. Thus, to force the default value from $:/config/DefaultSidebarTab to always be used at startup, you need to delete the qualified $:/state/tab/sidebar-... tiddler before your TiddlyWiki file is saved.

Fortunately, there is a VERY easy way to do this simply by creating a tiddler (e.g., “MyPublishFilter”), tagged with $:/tags/Global, containing the following text:

\define publishFilter() -[prefix[$:/state/tab/sidebar]]

That’s it. From now on, whenever you save your TiddlyWiki file, this filter is applied to the list of tiddlers that are to be saved. Note the use of -[prefix[$:/state/tab/sidebar]] in the filter. This means that all tiddlers with the indicated title prefix (regardless of any “qualified” numeric suffix) will automatically be skipped (because of the leading “-” on the filter) when saving the TiddlyWiki file.

The result is that whenever you reload the file, the default value in $:/config/DefaultSidebarTab is always used, which achieves your goal. Note that this also eliminates the need to use a $:/tags/StartupAction tiddler to remove the $:/state/tab/sidebar-... tiddler.

enjoy,
-e

7 Likes

Masterful, thank you! Fair to say that’s a better and more ‘integrated’ way of doing it than what Scott and I were doing.

Always thought “Open” tab should be the default on opening.

However, I just couldn’t get it to work for me. See Jim Carrey karate instructor (defense against the knife attack): “Like a lot of beginning students, you attacked me wrong. You’re supposed to come at me like this…”