Add Obsidian config scripts
This adds two scripts for Obsidian vaults. One will get the values of showInlineTitle for all vaults The other will change the value to false in all vaults
This commit is contained in:
parent
ef0a2367eb
commit
2c82137a71
5 changed files with 95 additions and 37 deletions
49
obsidian_hide_inlineTitle.py
Executable file
49
obsidian_hide_inlineTitle.py
Executable file
|
|
@ -0,0 +1,49 @@
|
|||
#!/usr/bin/env python3
|
||||
|
||||
import os
|
||||
import json
|
||||
|
||||
# Find all app.json config files for Obsidian
|
||||
# in all subdirectories of the specified directory
|
||||
# and change showInlineTitle to false
|
||||
# Assisted by ChatGPT
|
||||
|
||||
|
||||
def obsidian_hide_inline_title(parent_directory):
|
||||
try:
|
||||
# Loop through all folders and subfolders in the parent directory
|
||||
for root, dirs, files in os.walk(parent_directory):
|
||||
# Check if the current directory is named ".obsidian"
|
||||
if '.obsidian' in dirs:
|
||||
obsidian_folder_path = os.path.join(root, '.obsidian')
|
||||
# Look for a file named "app.json" in this folder
|
||||
app_json_path = os.path.join(obsidian_folder_path, 'app.json')
|
||||
if os.path.exists(app_json_path):
|
||||
# app_json_path = os.path.join(
|
||||
# obsidian_folder_path, 'app.json')
|
||||
# Open the JSON file for reading
|
||||
with open(app_json_path, 'r') as json_file:
|
||||
data = json.load(json_file)
|
||||
# Check if 'showInlineTitle' key exists
|
||||
# and change its value if it's 'true'
|
||||
if 'showInlineTitle' in data and data['showInlineTitle'] == True:
|
||||
data['showInlineTitle'] = False
|
||||
# Open the same JSON file for writing
|
||||
# and update its content
|
||||
with open(app_json_path, 'w') as json_file:
|
||||
json.dump(data, json_file, indent=4)
|
||||
print(
|
||||
f"Value of 'showInlineTitle' changed to false in '{app_json_path}'.")
|
||||
else:
|
||||
print(
|
||||
f"No action needed in '{app_json_path}'. 'showInlineTitle' either doesn't exist or is already false.")
|
||||
|
||||
except FileNotFoundError:
|
||||
print(f"Error: Directory '{parent_directory}' not found.")
|
||||
except json.JSONDecodeError:
|
||||
print(f"Error: Invalid JSON file found in '{parent_directory}'.")
|
||||
|
||||
|
||||
# Get the parent directory path from user input
|
||||
parent_directory = input("Enter the parent directory path: ")
|
||||
obsidian_hide_inline_title(parent_directory)
|
||||
Loading…
Add table
Add a link
Reference in a new issue