Close All Tabs to the Left or Right - Close Tabs in All Panes or Tabs in Active Pane #1566
Cr8zyIvan
started this conversation in
Templates Showcase
Replies: 1 comment
-
|
I've encountered a minor issue when using them: it appears that an unwanted newline character is inserted into the active document each time the command is executed. |
Beta Was this translation helpful? Give feedback.
0 replies
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Uh oh!
There was an error while loading. Please reload this page.
-
Here are four (4x) Scripts that Close All Tabs to the Left or Right throughout All Panes, or Close All Tabs to the Left or Right in the Active Pane. I could not find Plugins or Scripts that could what I wanted. There may be something better out there.
Note: Full Transparency - I had almost no experience with JavaScript before I started Hacking away to make a working Script. I used DeepSeek to Write the Code. I tested the Script in multiple use cases, and it works. However, I encourage all Users to inspect the Code and make sure for themselves that all is well before implementing it into their Obsidian.
Quick chronicle of the process: I had initially Prompted DeepSeek to Write a Templater Script to Close All Tabs to the Left and to the Right. After a bit of testing, I realized it closed ALL Tabs in one direction, even if they were in another Pane. I hadn't specified Closing the Tabs only in the Active Pane. After WAY too many back-and-forths, and always getting back a Script that Closed Odd Numbered Tabs, I Prompted DeepSeek: "You ALREADY closed all the Tabs to the Right. Now, instead of closing them, list them out, identify which ones belong to the Active Pane, and Close only those ones!" And now I have two sets of Scripts.
If you have any comments for improvement, don't hesitate to share. No ego has gone into creating this Code. Cheers!
Instructions for the Neophytes (like myself):
Each "Script" requires two Files: the .md File and the .js File. The goal of the .md File is only to call on the .js File, that contains the JavaScript (which is how I understand Templater works).
The .md Files are to be defined in the "Template hotkeys" section (in Templater's Settings). For each function (Close Left-All, Close Right-Active, etc.), you must add its corresponding .md File in this section.
Template hotkeys Section - The .md Files
Make sure your .md and .js Files are in the right Folders. (for .md Files, the Folder path must be defined in the "Folder templates" Section. for the .js Files, the Folder path must be defined in the "User script functions" section, in the "Script files folder location" subsection.) In the "Template hotkeys" section, add each .md File you have chosen to use.
User script functions - The .js Files
If you don't see your js Files (in the "Detected User Script(s)" subsection), make sure your Files are in the right Folder, and click on the Refresh Button.
Defining your Hotkeys
In the Obsidian Options Page, in the "Hotkeys" section, filter out the Scripts with "closetabs". Define the Hotkeys you want to use with the "Templater: Insert " functions.
Last Note
I just got the unpleasant surprise that sharing .js Files is not supported. Unfortunately, you will have to create the .js Files and paste the code I share here.
Extra little bit: If you're REALLY new to all of this, to create the .md and the .js Files, you can first create a text File (a .txt File) and Paste the Code I share here in each of the .txt Files (example: "CloseTabsRight_ActivePane.txt"). Once you've saved your Files, you then rename each File to it's corresponding Type: .md and .js (rename your .txt Files to "CloseTabsRight_ActivePane.md" and "CloseTabsRight_ActivePane.js". They MUST have the same name WITH the SAME letter casing (Upper and lower case letters. That was another, very unpleasant surprise I had to learn with JavaScript)). Windows will give you all sorts of warnings, and you click "Yes".
The Scripts
Close Tabs to the LEFT, in the ACTIVE Pane
CloseTabsLeft_ActivePane.js
CloseTabsLeft_ActivePane.md
Close Tabs to the RIGHT, in the ACTIVE Pane
CloseTabsRight_ActivePane.js
CloseTabsRight_ActivePane.md
Close Tabs to the LEFT, in ALL Panes
CloseTabsLeft_ALLPanes.js
CloseTabsLeft_ALLPanes.md
Close Tabs to the RIGHT, in ALL Panes
CloseTabsRight_ALLPanes.js
CloseTabsRight_ALLPanes.md
CloseTabsLeft_ActivePane.md
CloseTabsLeft_ALLPanes.md
CloseTabsRight_ActivePane.md
CloseTabsRight_ALLPanes.md
Beta Was this translation helpful? Give feedback.
All reactions