shell-scripts/obsidian_hide_inlineTitle.py

49 lines
2.2 KiB
Python
Raw Normal View History

#!/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)