42 lines
1.8 KiB
Python
42 lines
1.8 KiB
Python
|
|
#!/usr/bin/env python3
|
||
|
|
|
||
|
|
import os
|
||
|
|
import json
|
||
|
|
|
||
|
|
# Find all app.json config files for Obsidian
|
||
|
|
# in all subdirectories of the specified directory
|
||
|
|
# and show the value of showInlineTitle
|
||
|
|
# Assisted by ChatGPT
|
||
|
|
|
||
|
|
|
||
|
|
def get_show_inline_title_from_obsidian_folders(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):
|
||
|
|
# 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 print its value
|
||
|
|
if 'showInlineTitle' in data:
|
||
|
|
print(
|
||
|
|
f"In '{app_json_path}': showInlineTitle is {data['showInlineTitle']}")
|
||
|
|
else:
|
||
|
|
print(
|
||
|
|
f"In '{app_json_path}': showInlineTitle key does not exist.")
|
||
|
|
|
||
|
|
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: ")
|
||
|
|
get_show_inline_title_from_obsidian_folders(parent_directory)
|