Create list of links based on all open tabs

Things I have tried

I searched the forum for relevant information.

What I’m trying to do

When working on Obsidian mobile, I sometimes open up to around 10 tabs with no intention of closing them until I have accomplished my intended purpose for each. However, sometimes I want a clean slate and would prefer to simply keep one tab pinned with links to those 10 or so notes. Unfortunately I cannot think of an easy way to accomplish this. I am keeping this as Help instead of a Feature Request because I feel confident this is possible. Thanks in advance for any help!

1 Like

You can save open tabs as a Workspace (core plugin).

The process to go from open tabs to clean slate would be:

Setup (one time):

  1. Enable core plugin ‘Workspaces’
  2. Close all tabs
  3. Save as ‘blank’ workspace (menu > manage workspace layouts > enter name ‘blank’ > click save)

Usage:

  1. When tabs are open, save a new workspace named ‘session’ (menu > manage workspace layouts > enter name ‘session’ > click save)
  2. Load the ‘blank’ workspace (menu > manage workspace layouts, click load next to ‘blank’)

Screenshots below (from my phone)

2 Likes

Nice call! I am tempted to mark this as a solution, but I am going to hold out hope that potentially it is possible to generate the link list from tabs. In the end, I will likely just create a feature request or Plugin idea topic. Thanks for taking the time to respond. This is a very useful workaround in the meantime. I had totally forgotten about using the Workspace plugin when on mobile. Good stuff!

1 Like

There is another option but it is rather complicated and a bit fragile…

  1. Obtain tab names by querying the DOM (or maybe somewhere in the API)

  2. Ask a dataviewjs code block to create a list of links to files using these tab names.

  3. Place the dataviewjs code block in a templater template and output the result (not the query, we want the text)

  4. Bind the template to a shortcut

This is fragile because DOM elements can change. So it’s possible but very convoluted.

2 Likes

Well… I couldn’t help myself. Here’s some hacky code to produce this list. You may need to update it to filter out things you don’t want.

Save it as a Templater template.

<%* 
const dv = app.plugins.plugins.dataview.api; 

let tabHtmlElements = document.getElementsByClassName("workspace-tab-header")

let tabText = Array.from(tabHtmlElements)
	.map((tab) => (tab.textContent.trim()))
	.filter((name) => {
		// Filter out non-note tabs...
		
		let stardardTabNames = ["Files", "Search", "Starred", "Tags"]
		let isStandardTab = stardardTabNames.includes(name)
		
		let pluginTabNames = ["Advanced Tables", "Commander"] 
		let isPlugin = pluginTabNames.includes(name)

		let standardTabPrefixes = [
			"Outline of ", 
			"Backlinks for ",
			"Graph of "
		]
		let hasPrefix = standardTabPrefixes.some((element) => name.startsWith(element))

		let isBlank = name === "" 

		let shouldKeep = !isStandardTab 
			&& !isPlugin
			&& !hasPrefix
			&& !isBlank
			
		return shouldKeep;
	})

let uniqueTabs = [...new Set(tabText)];
let tabHeadingLinks = uniqueTabs.map( (item) => dv.fileLink(item))

tabHeadingLinks.map((tabLink) => (tR += tabLink + "\n"))
%>

Here’s a screenshot of it working…

3 Likes

Thanks so much! I can’t wait to get it working. I assume all I have to do is fence the code inside triple back ticks with dataviewjs in the template note. I will return tomorrow once I get it working to let you know.

This was very kind of you!

1 Like

You’re welcome!

No need to wrap with a dataviewjs code block.

To use it…

  1. Save it in your Templater templates folder.
  2. Open a note and position your cursor where you’d like the output
  3. Ask templater to apply the template

Templater Community plugin…

Enjoy :smiley:

4 Likes

Just finally tried this on Obsidian desktop and it worked like a charm. I realize now that the issue I was having yesterday on mobile was a result of the code formatting being lost when copying the code from the forum to a template of my phone. Once I synced the template copied on desktop, everything behaved perfectly. Thanks so much for this great solution!

1 Like

This topic was automatically closed 7 days after the last reply. New replies are no longer allowed.