Scripts - tkottke90/Obsidan-Styles GitHub Wiki
This is a collection of my Obsidian scripts which I use with my Obsidian Vault and the Templater plugin.
- Table of Contents
The following is a collection of scripts I have written which allow me to complete various tasks inside of my notebook. Some are specific to templates and others are more general purpose
Script: createResourceFolderWTroubleshooting.js
As a techolologist I am often tinkering with new technologies or trying to maintain specific tools/applications within my network of devices. Because of this I sometimes need to document issues that occur and the steps I take to resolve those issues. This script helps in that process by creating a root folder and a Troubleshooting
folder in the location you specify.
<project folder location>
├── Troubleshooting
└── <project name>.md
For example if I create a new project called Project A and I put that in my projects folder the structure would look like this:
Projects/Project A
├── Troubleshooting
└── Project A.md
To use this with Templater simply add the command to your template file and pass it the tp
instance:
<% tp.user.createResourceFolderWTroubleshooting(tp) %>
When the template executes, you will be prompted to enter the full path of your new resource folder:
<img here>
Make sure to include the name of our resource folder you wish to create in the full path. The script will use that name to create the new folder which contains the troubleshooting directory AND the new resource file.
Example
In the example above, I would have entered "Projects/Project A" into the prompt. This creates the "Project A" folder, the "Project A/Troubleshooting" folder, and the "Project A.md" file. If I had done simply "Projects" then it would have made a "Projects.md" file and a "Troubleshooting" folder in my Projects directory
Script: troubleshootingSetup.js
Along side the Directory Setup, I also want to ensure that the troubleshooting notes remain consistent. Specifically the naming of the files and the titles of the files. The rules I am following are:
- The filename should start with a date followed by the name (ex:
20240615 - Troubleshooting an issue
) - The title should follow the following format:
Troubleshooting - Troubleshooting an issue
To achieve this the script will prompt you to enter the name of your script and then create the file for you.
Inside of Obsidian, my template then includes the following line which will first rename the file and second return the title so it can be setup using Templater
# <% tp.user.renameAndTitle(tp, "What are you troubleshooting?") %>
As a software engineer I try to avoid duplicated code. I (like many) have found that it leads to extra long refactoring sessions when you have to find that very last instance in an otherwise simple fix OR one gets missed and it breaks production and you spend a ton of time trying to find/fix it only to realize what was missed. TLDR: DRY code saves lives.
Each of my utility modules (found in the lib
folder) are functions which return the module. Why did I do this? Because I was lazy and Obsidian seems to only allow the default export to be a function. So each of the modules (such as the obsidianUtils
) is a function which returns the inner functions:
module.export = (tp) => {
const { getFilesInFolder } = tp.user.obsidianUtils()
// ...
const files = getFilesInFolder(path)
}
Error Utilities is designed to help manage (what I see as) an otherwise annoying Error system. Currently only one function exists in the module at this time.
function throwError(type: string, message: string) => throws Error
Simply put this function helps with Errors since I do not want a separate class for each type of error but I do sometimes want to change what that Error Type is.
throwError('ValueError', 'Int cannot be used as a string')
// Error: Int cannot be used as a string'